function MultipleStaticContext::getRuntimeContexts

Same name and namespace in other branches
  1. 11.x core/modules/block/tests/modules/block_test/src/ContextProvider/MultipleStaticContext.php \Drupal\block_test\ContextProvider\MultipleStaticContext::getRuntimeContexts()

File

core/modules/block/tests/modules/block_test/src/ContextProvider/MultipleStaticContext.php, line 46

Class

MultipleStaticContext
Sets multiple contexts for a static value.

Namespace

Drupal\block_test\ContextProvider

Code

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.