core/lib/Drupal/Core/Block/BlockBase.php | 7 ++++--- core/lib/Drupal/Core/Cache/CacheContexts.php | 8 +++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/core/lib/Drupal/Core/Block/BlockBase.php b/core/lib/Drupal/Core/Block/BlockBase.php index 8a92e2a..796a4c7 100644 --- a/core/lib/Drupal/Core/Block/BlockBase.php +++ b/core/lib/Drupal/Core/Block/BlockBase.php @@ -225,9 +225,10 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta // choose to modify by: they must always be applied. $context_labels = array(); $all_contexts = \Drupal::service("cache_contexts")->getLabels(TRUE); - foreach (array_keys(CacheContexts::parseTokens($this->getRequiredCacheContexts())) as $context) { - $context_labels[] = $all_contexts[$context]; - unset($form['cache']['contexts']['#options'][$context]); + foreach (CacheContexts::parseTokens($this->getRequiredCacheContexts()) as $context) { + $context_id = $context[0]; + $context_labels[] = $all_contexts[$context_id]; + unset($form['cache']['contexts']['#options'][$context_id]); } $required_context_list = implode(', ', $context_labels); $form['cache']['contexts']['#description'] .= ' ' . t('This block is always varied by the following contexts: %required-context-list.', array('%required-context-list' => $required_context_list)); diff --git a/core/lib/Drupal/Core/Cache/CacheContexts.php b/core/lib/Drupal/Core/Cache/CacheContexts.php index d6146b5..4c0253f 100644 --- a/core/lib/Drupal/Core/Cache/CacheContexts.php +++ b/core/lib/Drupal/Core/Cache/CacheContexts.php @@ -137,9 +137,11 @@ protected function getService($context_id) { * An array of cache context tokens. * * @return array - * An array with the parsed results, with the cache context IDs as keys, and - * the associated parameter as value (for a calculated cache context), or - * NULL if there is no parameter. + * An array with the parsed results, with each result being an array + * containing: + * 1. the cache context ID + * 2. the associated parameter (for a calculated cache context), or NULL if + * there is no parameter. */ public static function parseTokens(array $context_tokens) { $contexts_with_parameters = [];