You are here

function node_access_grants in Drupal 8

Same name and namespace in other branches
  1. 4 modules/node.module \node_access_grants()
  2. 5 modules/node/node.module \node_access_grants()
  3. 6 modules/node/node.module \node_access_grants()
  4. 7 modules/node/node.module \node_access_grants()
  5. 9 core/modules/node/node.module \node_access_grants()

Fetches an array of permission IDs granted to the given user ID.

The implementation here provides only the universal "all" grant. A node access module should implement hook_node_grants() to provide a grant list for the user.

After the default grants have been loaded, we allow modules to alter the grants array by reference. This hook allows for complex business logic to be applied when integrating multiple node access modules.

Parameters

string $op: The operation that the user is trying to perform.

\Drupal\Core\Session\AccountInterface $account: The account object for the user performing the operation.

Return value

array An associative array in which the keys are realms, and the values are arrays of grants for those realms.

Related topics

5 calls to node_access_grants()
Access::query in core/modules/node/src/Plugin/views/filter/Access.php
See _node_access_where_sql() for a non-views query based implementation.
NodeAccessGrantsCacheContext::checkNodeGrants in core/modules/node/src/Cache/NodeAccessGrantsCacheContext.php
Checks the node grants for the given operation.
NodeGrantDatabaseStorage::access in core/modules/node/src/NodeGrantDatabaseStorage.php
Determines access to nodes based on node grants.
NodeGrantDatabaseStorage::alterQuery in core/modules/node/src/NodeGrantDatabaseStorage.php
Alters a query when node access is required.
NodeGrantDatabaseStorage::checkAll in core/modules/node/src/NodeGrantDatabaseStorage.php
Checks all grants for a given account.

File

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

Code

function node_access_grants($op, AccountInterface $account) {

  // Fetch node access grants from other modules.
  $grants = \Drupal::moduleHandler()
    ->invokeAll('node_grants', [
    $account,
    $op,
  ]);

  // Allow modules to alter the assigned grants.
  \Drupal::moduleHandler()
    ->alter('node_grants', $grants, $account, $op);
  return array_merge([
    'all' => [
      0,
    ],
  ], $grants);
}