function NodeAccessGrantsCacheContext::getContext

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

Overrides CalculatedCacheContextInterface::getContext

File

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

Class

NodeAccessGrantsCacheContext
Defines the node access view cache context service.

Namespace

Drupal\node\Cache

Code

public function getContext($operation = NULL) {
    // If the current user either can bypass node access then we don't need to
    // determine the exact node grants for the current user.
    if ($this->user
        ->hasPermission('bypass node access')) {
        return 'all';
    }
    // When no specific operation is specified, check the grants for all three
    // possible operations.
    if ($operation === NULL) {
        $result = [];
        foreach ([
            'view',
            'update',
            'delete',
        ] as $op) {
            $result[] = $this->checkNodeGrants($op);
        }
        return implode('-', $result);
    }
    else {
        return $this->checkNodeGrants($operation);
    }
}

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