Same name and namespace in other branches
  1. 10 core/modules/node/node.api.php \hook_node_grants()
  2. 4.6.x developer/hooks/core.php \hook_node_grants()
  3. 4.7.x developer/hooks/core.php \hook_node_grants()
  4. 5.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()

Inform the node access system what permissions the user has.

This hook is for implementation by node access modules. In this hook, the module grants a user different "grant IDs" within one or more "realms". In hook_node_access_records(), the realms and grant IDs are associated with permission to view, edit, and delete individual nodes.

The realms and grant IDs can be arbitrarily defined by your node access module; it is common to use role IDs as grant IDs, but that is not required. Your module could instead maintain its own list of users, where each list has an ID. In that case, the return value of this hook would be an array of the list IDs that this user is a member of.

A node access module may implement as many realms as necessary to properly define the access privileges for the nodes.

Parameters

$account: 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, and whose values are arrays of the grant IDs within this realm that this user is being granted.

For a detailed example, see node_access_example.module.

Related topics

2 invocations of hook_node_grants()
node_access_grants in modules/node/node.module
Fetch an array of permission IDs granted to the given user ID.
system_performance_settings in modules/system/system.admin.inc
Form builder; Configure site performance settings.

File

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

Code

function hook_node_grants($account, $op) {
  if (user_access('access private content', $account)) {
    $grants['example'] = array(
      1,
    );
  }
  $grants['example_owner'] = array(
    $account->uid,
  );
  return $grants;
}