diff --git a/core/lib/Drupal/Core/Cache/Context/AccountPermissionsCacheContext.php b/core/lib/Drupal/Core/Cache/Context/AccountPermissionsCacheContext.php index 2f1681c1ab0fbf8644896b77b27e319ec3ae56e2..be5d75409fc1b143b1d5bd38050775e945e47901 100644 --- a/core/lib/Drupal/Core/Cache/Context/AccountPermissionsCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/AccountPermissionsCacheContext.php @@ -49,7 +49,7 @@ public static function getLabel() { * {@inheritdoc} */ public function getContext() { - return 'ph.' . $this->permissionsHashGenerator->generate($this->user); + return $this->permissionsHashGenerator->generate($this->user); } /** diff --git a/core/lib/Drupal/Core/Cache/Context/CacheContextsManager.php b/core/lib/Drupal/Core/Cache/Context/CacheContextsManager.php index 4bf345978e2bf4ee376d65a011f7e2ed0b0ea7be..b01dc9eeadc9a934a5d2d0d21637cf94f4d626a2 100644 --- a/core/lib/Drupal/Core/Cache/Context/CacheContextsManager.php +++ b/core/lib/Drupal/Core/Cache/Context/CacheContextsManager.php @@ -120,9 +120,9 @@ public function convertTokensToKeys(array $context_tokens) { sort($optimized_tokens); $keys = []; - foreach (static::parseTokens($optimized_tokens) as $context) { + foreach (array_combine($optimized_tokens, static::parseTokens($optimized_tokens)) as $context_token => $context) { list($context_id, $parameter) = $context; - $keys[] = $this->getService($context_id)->getContext($parameter); + $keys[] = '[' . $context_token . ']=' . $this->getService($context_id)->getContext($parameter); } // Create the returned object and merge in the cacheability metadata. diff --git a/core/lib/Drupal/Core/Cache/Context/PagersCacheContext.php b/core/lib/Drupal/Core/Cache/Context/PagersCacheContext.php index dc6143b13607b1d00708d943883730004bbe529d..2c887d25f2c13d2d47c8a8b86b0eac365211bdc4 100644 --- a/core/lib/Drupal/Core/Cache/Context/PagersCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/PagersCacheContext.php @@ -34,10 +34,10 @@ public function getContext($pager_id = NULL) { // The value of the 'page' query argument contains the information that // controls *all* pagers. if ($pager_id === NULL) { - return 'pager' . $this->requestStack->getCurrentRequest()->query->get('page', ''); + return $this->requestStack->getCurrentRequest()->query->get('page', ''); } - return 'pager.' . $pager_id . '.' . pager_find_page($pager_id); + return $pager_id . '.' . pager_find_page($pager_id); } /** diff --git a/core/lib/Drupal/Core/Cache/Context/UserCacheContext.php b/core/lib/Drupal/Core/Cache/Context/UserCacheContext.php index 1a0357ac47f0a78da39cde33445179fad8710ba6..874558bc19294f0bef59c5adec80401dc64cef58 100644 --- a/core/lib/Drupal/Core/Cache/Context/UserCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/UserCacheContext.php @@ -27,7 +27,7 @@ public static function getLabel() { * {@inheritdoc} */ public function getContext() { - return "u." . $this->user->id(); + return $this->user->id(); } /** diff --git a/core/lib/Drupal/Core/Cache/Context/UserRolesCacheContext.php b/core/lib/Drupal/Core/Cache/Context/UserRolesCacheContext.php index 1181634cba640b68524e5e3888bd0976ff6d5e2e..94784f7cd12b1c231bb9fa3820aa1c041338968d 100644 --- a/core/lib/Drupal/Core/Cache/Context/UserRolesCacheContext.php +++ b/core/lib/Drupal/Core/Cache/Context/UserRolesCacheContext.php @@ -40,10 +40,10 @@ public function getContext($role = NULL) { return 'is-super-user'; } if ($role === NULL) { - return 'r.' . implode(',', $this->user->getRoles()); + return implode(',', $this->user->getRoles()); } else { - return 'r.' . $role . '.' . (in_array($role, $this->user->getRoles()) ? '0' : '1'); + return (in_array($role, $this->user->getRoles()) ? '0' : '1'); } } diff --git a/core/modules/book/src/Cache/BookNavigationCacheContext.php b/core/modules/book/src/Cache/BookNavigationCacheContext.php index 9dbe1dbe4a4a21cbea4686c1502571dfab337cc2..d165b95a3c57e24f32986b8f4c42e7c8b7d30e9e 100644 --- a/core/modules/book/src/Cache/BookNavigationCacheContext.php +++ b/core/modules/book/src/Cache/BookNavigationCacheContext.php @@ -68,7 +68,7 @@ public function getContext() { // If we're looking at a book node, get the trail for that node. $active_trail = $this->container->get('book.manager') ->getActiveTrailIds($node->book['bid'], $node->book); - return 'book.' . implode('|', $active_trail); + return implode('|', $active_trail); } /** diff --git a/core/modules/system/src/Tests/Pager/PagerTest.php b/core/modules/system/src/Tests/Pager/PagerTest.php index c556c292af67ced761e20080b0f8317f01bfff00..133c90cb265ae66882dfac6c3fe4201b516e8887 100644 --- a/core/modules/system/src/Tests/Pager/PagerTest.php +++ b/core/modules/system/src/Tests/Pager/PagerTest.php @@ -76,14 +76,14 @@ protected function testPagerQueryParametersAndCacheContext() { // First page. $this->drupalGet('pager-test/query-parameters'); $this->assertText(t('Pager calls: 0'), 'Initial call to pager shows 0 calls.'); - $this->assertText('pager.0.0'); + $this->assertText('[url.query_args.pagers:0]=0.0'); $this->assertCacheContext('url.query_args'); // Go to last page, the count of pager calls need to go to 1. $elements = $this->xpath('//li[contains(@class, :class)]/a', array(':class' => 'pager__item--last')); $this->drupalGet($this->getAbsoluteUrl($elements[0]['href'])); $this->assertText(t('Pager calls: 1'), 'First link call to pager shows 1 calls.'); - $this->assertText('pager.0.60'); + $this->assertText('[url.query_args.pagers:0]=0.60'); $this->assertCacheContext('url.query_args'); // Go back to first page, the count of pager calls need to go to 2. @@ -91,7 +91,7 @@ protected function testPagerQueryParametersAndCacheContext() { $this->drupalGet($this->getAbsoluteUrl($elements[0]['href'])); $this->drupalGet($GLOBALS['base_root'] . parse_url($this->getUrl())['path'] . $elements[0]['href'], array('external' => TRUE)); $this->assertText(t('Pager calls: 2'), 'Second link call to pager shows 2 calls.'); - $this->assertText('pager.0.0'); + $this->assertText('[url.query_args.pagers:0]=0.0'); $this->assertCacheContext('url.query_args'); } diff --git a/core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php b/core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php index 56402aaf1642990d6fa81598d12fbdb01cd0528f..db8d7b70ae95be582e0b06ce60948a46a865dfbd 100644 --- a/core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php @@ -96,9 +96,9 @@ public function testConvertTokensToKeys() { ]); $expected = [ - 'baz.cnenzrgreN', - 'baz.cnenzrgreO', - 'bar', + '[baz:parameterA]=cnenzrgreN', + '[baz:parameterB]=cnenzrgreO', + '[foo]=bar', ]; $this->assertEquals($expected, $new_keys->getKeys()); } @@ -267,7 +267,7 @@ public function getContext($parameter = NULL) { if (!is_string($parameter) || strlen($parameter) === 0) { throw new \Exception(); } - return 'baz.' . str_rot13($parameter); + return str_rot13($parameter); } /**