function CurrentUserContext::getRuntimeContexts
Same name in other branches
- 8.9.x core/modules/user/src/ContextProvider/CurrentUserContext.php \Drupal\user\ContextProvider\CurrentUserContext::getRuntimeContexts()
- 10 core/modules/user/src/ContextProvider/CurrentUserContext.php \Drupal\user\ContextProvider\CurrentUserContext::getRuntimeContexts()
- 11.x core/modules/user/src/ContextProvider/CurrentUserContext.php \Drupal\user\ContextProvider\CurrentUserContext::getRuntimeContexts()
Overrides ContextProviderInterface::getRuntimeContexts
1 call to CurrentUserContext::getRuntimeContexts()
- CurrentUserContext::getAvailableContexts in core/
modules/ user/ src/ ContextProvider/ CurrentUserContext.php - Gets all available contexts for the purposes of configuration.
File
-
core/
modules/ user/ src/ ContextProvider/ CurrentUserContext.php, line 49
Class
- CurrentUserContext
- Sets the current user as a context.
Namespace
Drupal\user\ContextProviderCode
public function getRuntimeContexts(array $unqualified_context_ids) {
$current_user = $this->userStorage
->load($this->account
->id());
if ($current_user) {
// @todo Do not validate protected fields to avoid bug in TypedData,
// remove this in https://www.drupal.org/project/drupal/issues/2934192.
$current_user->_skipProtectedUserFieldConstraint = TRUE;
$context = EntityContext::fromEntity($current_user, $this->t('Current user'));
}
else {
// If not user is available, provide an empty context object.
$context = EntityContext::fromEntityTypeId('user', $this->t('Current user'));
}
$cacheability = new CacheableMetadata();
$cacheability->setCacheContexts([
'user',
]);
$context->addCacheableDependency($cacheability);
$result = [
'current_user' => $context,
];
return $result;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.