function node_node_access in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/node/node.module \node_node_access()
Implements hook_node_access().
Related topics
File
- core/
modules/ node/ node.module, line 903 - The core module that allows content to be submitted to the site.
Code
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()
->cacheUntilEntityChanges($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()
->cacheUntilEntityChanges($node);
}
default:
// No opinion.
return AccessResult::neutral();
}
}