function UserRolesCacheContext::getContext
Same name in other branches
- 9 core/lib/Drupal/Core/Cache/Context/UserRolesCacheContext.php \Drupal\Core\Cache\Context\UserRolesCacheContext::getContext()
- 8.9.x core/lib/Drupal/Core/Cache/Context/UserRolesCacheContext.php \Drupal\Core\Cache\Context\UserRolesCacheContext::getContext()
- 10 core/lib/Drupal/Core/Cache/Context/UserRolesCacheContext.php \Drupal\Core\Cache\Context\UserRolesCacheContext::getContext()
Overrides CalculatedCacheContextInterface::getContext
File
-
core/
lib/ Drupal/ Core/ Cache/ Context/ UserRolesCacheContext.php, line 29
Class
- UserRolesCacheContext
- Defines the UserRolesCacheContext service, for "per role" caching.
Namespace
Drupal\Core\Cache\ContextCode
public function getContext($role = NULL) {
if ($role === NULL) {
return implode(',', $this->user
->getRoles());
}
else {
return in_array($role, $this->user
->getRoles()) ? 'true' : 'false';
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.