function MultipleStaticContext::getRuntimeContexts
Same name in other branches
- 9 core/modules/block/tests/modules/block_test/src/ContextProvider/MultipleStaticContext.php \Drupal\block_test\ContextProvider\MultipleStaticContext::getRuntimeContexts()
- 8.9.x core/modules/block/tests/modules/block_test/src/ContextProvider/MultipleStaticContext.php \Drupal\block_test\ContextProvider\MultipleStaticContext::getRuntimeContexts()
- 10 core/modules/block/tests/modules/block_test/src/ContextProvider/MultipleStaticContext.php \Drupal\block_test\ContextProvider\MultipleStaticContext::getRuntimeContexts()
Overrides ContextProviderInterface::getRuntimeContexts
1 call to MultipleStaticContext::getRuntimeContexts()
- MultipleStaticContext::getAvailableContexts in core/
modules/ block/ tests/ modules/ block_test/ src/ ContextProvider/ MultipleStaticContext.php - Gets all available contexts for the purposes of configuration.
File
-
core/
modules/ block/ tests/ modules/ block_test/ src/ ContextProvider/ MultipleStaticContext.php, line 48
Class
- MultipleStaticContext
- Sets multiple contexts for a static value.
Namespace
Drupal\block_test\ContextProviderCode
public function getRuntimeContexts(array $unqualified_context_ids) {
$current_user = $this->userStorage
->load($this->account
->id());
$context1 = EntityContext::fromEntity($current_user, 'User A');
$context2 = EntityContext::fromEntity($current_user, 'User B');
$cacheability = new CacheableMetadata();
$cacheability->setCacheContexts([
'user',
]);
$context1->addCacheableDependency($cacheability);
$context2->addCacheableDependency($cacheability);
return [
'userA' => $context1,
'userB' => $context2,
];
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.