Same name and namespace in other branches
  1. 10 core/modules/node/node.api.php \hook_node_grants()
  2. 4.7.x developer/hooks/core.php \hook_node_grants()
  3. 5.x developer/hooks/core.php \hook_node_grants()
  4. 6.x developer/hooks/core.php \hook_node_grants()
  5. 7.x modules/node/node.api.php \hook_node_grants()
  6. 8.9.x core/modules/node/node.api.php \hook_node_grants()
  7. 9 core/modules/node/node.api.php \hook_node_grants()

Grant access to nodes.

This hook is for implementation by node access modules. In addition to managing entries in the node_access table in the database, such modules must implement this hook to inform Drupal which "grants" the current user has. For example, in a role-based access scheme, this function would return a list of the roles the user belongs to.

Parameters

$user: The user object whose grants are requested.

$op: The node operation to be performed, such as "view", "update", or "delete".

Return value

An array whose keys are "realms" of grants such as "user" or "role", and whose values are linear lists of grant IDs.

For a detailed example, see node_access_example.module.

Related topics

1 function implements hook_node_grants()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

node_access_example_node_grants in developer/examples/node_access_example.module
Implementation of hook_node_grants().
1 invocation of hook_node_grants()
node_access_grants in modules/node.module
Fetch an array of permission IDs granted to the given user ID.

File

developer/hooks/core.php, line 667
These are the hooks that are invoked by the Drupal core.

Code

function hook_node_grants($user, $op) {
  $grants = array();
  if ($op == 'view') {
    if (user_access('access content')) {
      $grants[] = 0;
    }
    if (user_access('access private content')) {
      $grants[] = 1;
    }
  }
  if ($op == 'update' || $op == 'delete') {
    if (user_access('edit content')) {
      $grants[] = 0;
    }
    if (user_access('edit private content')) {
      $grants[] = 1;
    }
  }
  return array(
    'example' => $grants,
  );
}