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.

Parameters

\Drupal\Core\Entity\EntityInterface $node: The $node to acquire grants for.

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

Related topics

3 calls to node_access_acquire_grants()
NodeStorageController::postSave in drupal/core/modules/node/lib/Drupal/node/NodeStorageController.php
Overrides Drupal\Core\Entity\DatabaseStorageController::postSave().
node_access_rebuild in drupal/core/modules/node/node.module
Rebuilds the node access database.
_node_access_rebuild_batch_operation in drupal/core/modules/node/node.module
Performs batch operation for node_access_rebuild().

File

drupal/core/modules/node/node.module, line 2867
The core module that allows content to be submitted to the site.

Code

function node_access_acquire_grants(EntityInterface $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,
    );
  }
  _node_access_write_grants($node, $grants, NULL, $delete);
}