You are here

public function CacheContexts::convertTokensToKeys in Render cache 7.2

Converts cache context tokens to string representations of the context.

Cache keys may either be static (just strings) or tokens (placeholders that are converted to static keys by the @cache_contexts service, depending depending on the request). This is the default cache contexts service.

Parameters

array $keys: An array of cache keys that may or may not contain cache context tokens.

Return value

array A copy of the input, with cache context tokens converted.

File

lib/Drupal/Core/Cache/CacheContexts.php, line 89
Contains \Drupal\Core\Cache\CacheContexts.

Class

CacheContexts
Defines the CacheContexts service.

Namespace

Drupal\Core\Cache

Code

public function convertTokensToKeys(array $keys) {
  $context_keys = array_intersect($keys, $this
    ->getAll());
  $new_keys = $keys;

  // Iterate over the indices instead of the values so that the order of the
  // cache keys are preserved.
  foreach (array_keys($context_keys) as $index) {
    $new_keys[$index] = $this
      ->getContext($keys[$index]);
  }
  return $new_keys;
}