hook_node_grants

5 core.php hook_node_grants($account, $op)
6 core.php hook_node_grants($account, $op)
7 node.api.php hook_node_grants($account, $op)
8 node.api.php hook_node_grants($account, $op)

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()

1 invocation of hook_node_grants()

File

developer/hooks/core.php, line 654
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);
}
Login or register to post comments