I have a node type ‘faq’. For node type ‘faq’ I need to remove the tab ‘node clone’.
For that I have done the following codes. In node_clone.routing.yml I have the following code
node_clone.prepopulate_node: path: '/node/{node}/clone/prepopulate' defaults: _title: 'Clone content' _controller: 'node_clone.form_controller:getContentResult' requirements: _custom_access: 'node_clone.form_controller:access' #_node_add_access: 'node:{node_type}' node: 'd+' options: _node_operation_route: TRUE parameters: node: type: 'entity:node'
In my controller file
public function access(AccountInterface $account, NodeInterface $node) { $node_type = ($node->getType()); if($node_type=="faq") { $access = new AccessResultForbidden(); } if ($account->hasPermission('clone node') || ($node->uid->value === $account->id() && $account->hasPermission('clone own nodes'))) { $access = new AccessResultAllowed(); } else { $access = new AccessResultForbidden(); } $access->addCacheableDependency($node); $access->cachePerPermissions(); if ($access->isAllowed()) { $access = $access->andIf($node->access('view', $account, TRUE)); } if ($access->isAllowed()) { $node_type = NodeType::load($node->getType()); $access = $access->andIf($this->nodeAddAccessCheck->access($account, $node_type)); } return $access; }
Please help me to find out what’s wrong with my code? Is this enough or I should do something else?