node_node_access(NodeInterface $node, $op, $account)
Implements hook_node_access().
function node_node_access(NodeInterface $node, $op, $account) { $type = $node->bundle(); switch ($op) { case 'create': return AccessResult::allowedIfHasPermission($account, 'create ' . $type . ' content'); case 'update': if ($account->hasPermission('edit any ' . $type . ' content', $account)) { return AccessResult::allowed()->cachePerPermissions(); } else { return AccessResult::allowedIf($account->hasPermission('edit own ' . $type . ' content', $account) && ($account->id() == $node->getOwnerId()))->cachePerPermissions()->cachePerUser()->addCacheableDependency($node); } case 'delete': if ($account->hasPermission('delete any ' . $type . ' content', $account)) { return AccessResult::allowed()->cachePerPermissions(); } else { return AccessResult::allowedIf($account->hasPermission('delete own ' . $type . ' content', $account) && ($account->id() == $node->getOwnerId()))->cachePerPermissions()->cachePerUser()->addCacheableDependency($node); } default: // No opinion. return AccessResult::neutral(); } }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!modules!node!node.module/function/node_node_access/8.1.x