public function NodeAccessGrantsCacheContext::getContext in Drupal 9
Same name and namespace in other branches
- 8 core/modules/node/src/Cache/NodeAccessGrantsCacheContext.php \Drupal\node\Cache\NodeAccessGrantsCacheContext::getContext()
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\CacheCode
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);
}
}