NodeAccessGrantsCacheContext::getContext

public NodeAccessGrantsCacheContext::getContext($operation = NULL)

Returns the string representation of the cache context.

A cache context service's name is used as a token (placeholder) cache key, and is then replaced with the string returned by this method.

Parameters

string|null $parameter: The parameter, or NULL to indicate all possible parameter values.

Return value

string The string representation of the cache context. When $parameter is NULL, a value representing all possible parameters must be generated.

Throws

\LogicException Thrown if the passed in parameter is invalid.

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);
  }
}
doc_Drupal
2016-10-29 09:30:33
Comments
Leave a Comment

Please login to continue.