function NodeAccessGrantsCacheContext::checkNodeGrants

Same name in other branches
  1. 8.9.x core/modules/node/src/Cache/NodeAccessGrantsCacheContext.php \Drupal\node\Cache\NodeAccessGrantsCacheContext::checkNodeGrants()
  2. 10 core/modules/node/src/Cache/NodeAccessGrantsCacheContext.php \Drupal\node\Cache\NodeAccessGrantsCacheContext::checkNodeGrants()
  3. 11.x core/modules/node/src/Cache/NodeAccessGrantsCacheContext.php \Drupal\node\Cache\NodeAccessGrantsCacheContext::checkNodeGrants()

Checks the node grants for the given operation.

Parameters

string $operation: The operation to check the node grants for.

Return value

string The string representation of the cache context.

1 call to NodeAccessGrantsCacheContext::checkNodeGrants()
NodeAccessGrantsCacheContext::getContext in core/modules/node/src/Cache/NodeAccessGrantsCacheContext.php
Returns the string representation of the cache context.

File

core/modules/node/src/Cache/NodeAccessGrantsCacheContext.php, line 63

Class

NodeAccessGrantsCacheContext
Defines the node access view cache context service.

Namespace

Drupal\node\Cache

Code

protected function checkNodeGrants($operation) {
    // When checking the grants for the 'view' operation and the current user
    // has a global view grant (i.e. a view grant for node ID 0) — note that
    // this is automatically the case if no node access modules exist (no
    // hook_node_grants() implementations) then we don't need to determine the
    // exact node view grants for the current user.
    if ($operation === 'view' && node_access_view_all_nodes($this->user)) {
        return 'view.all';
    }
    $grants = node_access_grants($operation, $this->user);
    $grants_context_parts = [];
    foreach ($grants as $realm => $gids) {
        $grants_context_parts[] = $realm . ':' . implode(',', $gids);
    }
    return $operation . '.' . implode(';', $grants_context_parts);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.