function Cache::mergeContexts

Same name and namespace in other branches
  1. 8.9.x core/lib/Drupal/Core/Cache/Cache.php \Drupal\Core\Cache\Cache::mergeContexts()
  2. 10 core/lib/Drupal/Core/Cache/Cache.php \Drupal\Core\Cache\Cache::mergeContexts()
  3. 11.x core/lib/Drupal/Core/Cache/Cache.php \Drupal\Core\Cache\Cache::mergeContexts()

Merges arrays of cache contexts and removes duplicates.

Parameters

string[] ...: Cache contexts arrays to merge.

Return value

string[] The merged array of cache contexts.

22 calls to Cache::mergeContexts()
AssertPageCacheContextsAndTagsTrait::assertCacheContexts in core/modules/system/tests/src/Functional/Cache/AssertPageCacheContextsAndTagsTrait.php
Ensures that some cache contexts are present in the current response.
BlockContentCacheTagsTest::testBlock in core/modules/block_content/tests/src/Functional/BlockContentCacheTagsTest.php
Tests that the block is cached with the correct contexts and tags.
BlockViewBuilder::viewMultiple in core/modules/block/src/BlockViewBuilder.php
Builds the render array for the provided entities.
BlockViewBuilderTest::assertBlockRenderedWithExpectedCacheability in core/modules/block/tests/src/Kernel/BlockViewBuilderTest.php
Asserts that a block is built/rendered/cached with expected cacheability.
BlockViewBuilderTest::testBlockViewBuilderBuildAlter in core/modules/block/tests/src/Kernel/BlockViewBuilderTest.php
Tests block build altering.

... See full list

File

core/lib/Drupal/Core/Cache/Cache.php, line 29

Class

Cache
Helper methods for cache.

Namespace

Drupal\Core\Cache

Code

public static function mergeContexts(array ...$cache_contexts) {
  $cache_contexts = array_unique(array_merge(...$cache_contexts));
  assert(\Drupal::service('cache_contexts_manager')->assertValidTokens($cache_contexts), sprintf('Failed to assert that "%s" are valid cache contexts.', implode(', ', $cache_contexts)));
  return $cache_contexts;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.