function nodeaccess_node_access in Nodeaccess 8
Same name and namespace in other branches
- 8.2 nodeaccess.module \nodeaccess_node_access()
- 7 nodeaccess.module \nodeaccess_node_access()
Implements hook_node_access().
File
- ./
nodeaccess.module, line 262 - Control access to site content based on the users and roles.
Code
function nodeaccess_node_access(NodeInterface $node, $op, $account) {
$settings = \Drupal::configFactory()
->get('nodeaccess.settings');
$role_map = $settings
->get('role_map');
switch ($op) {
case 'update':
case 'delete':
// If the node belongs to a deleted user.
if ($account
->id() == 0 && $node
->getOwnerId() == 0) {
// We check if the role has particular access to this node.
$grants = _nodeaccess_get_grants($node);
$anonymous_rid = $role_map[DRUPAL_ANONYMOUS_RID];
// If anonymous has rights to this node, we allow them.
if ($grants['rid'][$anonymous_rid]['grant_update'] && $op == 'update' || $grants['rid'][$anonymous_rid]['grant_delete'] && $op == 'delete') {
return AccessResult::Allowed();
}
return AccessResult::forbidden();
}
break;
}
}