8.2.x RefinableCacheableDependencyTrait.php public RefinableCacheableDependencyTrait::addCacheContexts(array $cache_contexts)
8.0.x RefinableCacheableDependencyTrait.php public RefinableCacheableDependencyTrait::addCacheContexts(array $cache_contexts)
8.1.x RefinableCacheableDependencyTrait.php public RefinableCacheableDependencyTrait::addCacheContexts(array $cache_contexts)
8.3.x RefinableCacheableDependencyTrait.php public RefinableCacheableDependencyTrait::addCacheContexts(array $cache_contexts)

Adds cache contexts.

Parameters

string[] $cache_contexts: The cache contexts to be added.

Return value

$this

Overrides RefinableCacheableDependencyInterface::addCacheContexts

3 calls to RefinableCacheableDependencyTrait::addCacheContexts()
AccessResult::cachePerPermissions in core/lib/Drupal/Core/Access/AccessResult.php
Convenience method, adds the "user.permissions" cache context.
AccessResult::cachePerUser in core/lib/Drupal/Core/Access/AccessResult.php
Convenience method, adds the "user" cache context.
RefinableCacheableDependencyTrait::addCacheableDependency in core/lib/Drupal/Core/Cache/RefinableCacheableDependencyTrait.php
Adds a dependency on an object: merges its cacheability metadata.

File

core/lib/Drupal/Core/Cache/RefinableCacheableDependencyTrait.php, line 71

Class

RefinableCacheableDependencyTrait
Trait for \Drupal\Core\Cache\RefinableCacheableDependencyInterface.

Namespace

Drupal\Core\Cache

Code

public function addCacheContexts(array $cache_contexts) {
  if ($cache_contexts) {
    $this->cacheContexts = Cache::mergeContexts($this->cacheContexts, $cache_contexts);
  }
  return $this;
}