function CacheContextsManager::getLabels

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

Provides an array of available cache context labels.

To be used in cache configuration forms.

Parameters

bool $include_calculated_cache_contexts: Whether to also return calculated cache contexts. Default to FALSE.

Return value

array An array of available cache contexts and corresponding labels.

File

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

Class

CacheContextsManager
Converts cache context tokens into cache keys.

Namespace

Drupal\Core\Cache\Context

Code

public function getLabels($include_calculated_cache_contexts = FALSE) {
    $with_labels = [];
    foreach ($this->contexts as $context) {
        $service = $this->getService($context);
        if (!$include_calculated_cache_contexts && $service instanceof CalculatedCacheContextInterface) {
            continue;
        }
        $with_labels[$context] = $service->getLabel();
    }
    return $with_labels;
}

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