function CacheContextsManager::parseTokens

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

Parses cache context tokens into context IDs and optional parameters.

Parameters

string[] $context_tokens: An array of cache context tokens.

Return value

array An array with the parsed results, with each result being an array containing:

  • The cache context ID.
  • The associated parameter (for a calculated cache context), or NULL if there is no parameter.
1 call to CacheContextsManager::parseTokens()
CacheContextsManager::convertTokensToKeys in core/lib/Drupal/Core/Cache/Context/CacheContextsManager.php
Converts cache context tokens to cache keys.

File

core/lib/Drupal/Core/Cache/Context/CacheContextsManager.php, line 238

Class

CacheContextsManager
Converts cache context tokens into cache keys.

Namespace

Drupal\Core\Cache\Context

Code

public static function parseTokens(array $context_tokens) {
    $contexts_with_parameters = [];
    foreach ($context_tokens as $context) {
        $context_id = $context;
        $parameter = NULL;
        if (str_contains($context, ':')) {
            [
                $context_id,
                $parameter,
            ] = explode(':', $context, 2);
        }
        $contexts_with_parameters[] = [
            $context_id,
            $parameter,
        ];
    }
    return $contexts_with_parameters;
}

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