function node_access_acquire_grants

Gets the list of node access grants and writes them to the database.

This function is called when a node is saved, and can also be called by modules if something other than a node save causes node access permissions to change. It collects all node access grants for the node from hook_node_access_records() implementations, allows these grants to be altered via hook_node_access_records_alter() implementations, and saves the collected and altered grants to the database.


$node: The $node to acquire grants for.

$delete: Whether to delete existing node access records before inserting new ones. Defaults to TRUE.

Related topics

3 calls to node_access_acquire_grants()
node_access_rebuild in drupal/modules/node/node.module
Rebuilds the node access database.
node_save in drupal/modules/node/node.module
Saves changes to a node or adds a new node.
_node_access_rebuild_batch_operation in drupal/modules/node/node.module
Implements callback_batch_operation().


drupal/modules/node/node.module, line 3494
The core that allows content to be submitted to the site. Modules and scripts may programmatically submit nodes using the usual form API pattern.


function node_access_acquire_grants($node, $delete = TRUE) {
  $grants = module_invoke_all('node_access_records', $node);

  // Let modules alter the grants.
  drupal_alter('node_access_records', $grants, $node);

  // If no grants are set and the node is published, then use the default grant.
  if (empty($grants) && !empty($node->status)) {
    $grants[] = array(
      'realm' => 'all',
      'gid' => 0,
      'grant_view' => 1,
      'grant_update' => 0,
      'grant_delete' => 0,
  else {

    // Retain grants by highest priority.
    $grant_by_priority = array();
    foreach ($grants as $g) {
      $grant_by_priority[intval($g['priority'])][] = $g;
    $grants = array_shift($grant_by_priority);
  node_access_write_grants($node, $grants, NULL, $delete);