function NodeAccessGrantsCacheContext::getCacheableMetadata
Same name in other branches
- 9 core/modules/node/src/Cache/NodeAccessGrantsCacheContext.php \Drupal\node\Cache\NodeAccessGrantsCacheContext::getCacheableMetadata()
- 10 core/modules/node/src/Cache/NodeAccessGrantsCacheContext.php \Drupal\node\Cache\NodeAccessGrantsCacheContext::getCacheableMetadata()
- 11.x core/modules/node/src/Cache/NodeAccessGrantsCacheContext.php \Drupal\node\Cache\NodeAccessGrantsCacheContext::getCacheableMetadata()
Overrides CalculatedCacheContextInterface::getCacheableMetadata
File
-
core/
modules/ node/ src/ Cache/ NodeAccessGrantsCacheContext.php, line 84
Class
- NodeAccessGrantsCacheContext
- Defines the node access view cache context service.
Namespace
Drupal\node\CacheCode
public function getCacheableMetadata($operation = NULL) {
$cacheable_metadata = new CacheableMetadata();
if (!\Drupal::moduleHandler()->getImplementations('node_grants')) {
return $cacheable_metadata;
}
// The node grants may change if the user is updated. (The max-age is set to
// zero below, but sites may override this cache context, and change it to a
// non-zero value. In such cases, this cache tag is needed for correctness.)
$cacheable_metadata->setCacheTags([
'user:' . $this->user
->id(),
]);
// If the site is using node grants, this cache context can not be
// optimized.
return $cacheable_metadata->setCacheMaxAge(0);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.