core/lib/Drupal/Core/Cache/CacheContexts.php | 1 + core/lib/Drupal/Core/Render/Renderer.php | 1 - core/lib/Drupal/Core/Render/RendererInterface.php | 6 +++--- core/modules/filter/src/FilterProcessResult.php | 2 +- core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php | 6 ++---- core/tests/Drupal/Tests/Core/Cache/CacheContextsTest.php | 2 +- 6 files changed, 8 insertions(+), 10 deletions(-) diff --git a/core/lib/Drupal/Core/Cache/CacheContexts.php b/core/lib/Drupal/Core/Cache/CacheContexts.php index 4c0253f..33f86b1 100644 --- a/core/lib/Drupal/Core/Cache/CacheContexts.php +++ b/core/lib/Drupal/Core/Cache/CacheContexts.php @@ -105,6 +105,7 @@ public function getLabels($include_calculated_cache_contexts = FALSE) { * @throws \InvalidArgumentException */ public function convertTokensToKeys(array $context_tokens) { + sort($context_tokens); $keys = []; foreach (static::parseTokens($context_tokens) as $context) { list($context_id, $parameter) = $context; diff --git a/core/lib/Drupal/Core/Render/Renderer.php b/core/lib/Drupal/Core/Render/Renderer.php index 31d1ebd..0be7a89 100644 --- a/core/lib/Drupal/Core/Render/Renderer.php +++ b/core/lib/Drupal/Core/Render/Renderer.php @@ -634,7 +634,6 @@ protected function createCacheID(array $elements) { elseif (isset($elements['#cache']['keys'])) { $cid_parts = $elements['#cache']['keys']; if (isset($elements['#cache']['contexts'])) { - sort($elements['#cache']['contexts']); $contexts = $this->cacheContexts->convertTokensToKeys($elements['#cache']['contexts']); $cid_parts = array_merge($cid_parts, $contexts); } diff --git a/core/lib/Drupal/Core/Render/RendererInterface.php b/core/lib/Drupal/Core/Render/RendererInterface.php index c4fbe12..a42eb5f 100644 --- a/core/lib/Drupal/Core/Render/RendererInterface.php +++ b/core/lib/Drupal/Core/Render/RendererInterface.php @@ -131,7 +131,7 @@ public function renderPlain(&$elements); * It is for that case that we must store the current (pre-bubbling) cache * ID, so that we can compare it with the new (post-bubbling) cache ID * when writing to the cache. We store the current cache ID in - * #cid_pre_bubbling. + * $pre_bubbling_cid. * - If this element has #type defined and the default attributes for this * element have not already been merged in (#defaults_loaded = TRUE) then * the defaults for this type of element, defined in hook_element_info(), @@ -231,10 +231,10 @@ public function renderPlain(&$elements); * - If this element has #cache defined, the rendered output of this element * is saved to Renderer::render()'s internal cache. This includes the * changes made by #post_render. - * At the same time, if #cid_pre_bubbling is set, it is compared to the + * At the same time, if $pre_bubbling_cid is set, it is compared to the * calculated cache ID. If they are different, then a redirecting cache * item is created, containing the #cache metadata of the current element, - * and written to cache using the value of #cid_pre_bubbling as the cache + * and written to cache using the value of $pre_bubbling_cid as the cache * ID. This ensures the pre-bubbling ("wrong") cache ID redirects to the * post-bubbling ("right") cache ID. * - If this element has an array of #post_render_cache functions defined, diff --git a/core/modules/filter/src/FilterProcessResult.php b/core/modules/filter/src/FilterProcessResult.php index 167478d..e8487d1 100644 --- a/core/modules/filter/src/FilterProcessResult.php +++ b/core/modules/filter/src/FilterProcessResult.php @@ -200,7 +200,7 @@ public function getCacheContexts() { * @return $this */ public function addCacheContexts(array $cache_contexts) { - $this->cacheContexts = Cache::mergeContexts($this->cacheTags, $cache_contexts); + $this->cacheContexts = Cache::mergeContexts($this->cacheContexts, $cache_contexts); return $this; } diff --git a/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php b/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php index 580cada..0b0728e 100644 --- a/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php +++ b/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php @@ -613,7 +613,6 @@ public function testReferencedEntity() { protected function createCacheId(array $keys, array $contexts) { $cid_parts = $keys; - sort($contexts); $contexts = \Drupal::service('cache_contexts')->convertTokensToKeys($contexts); $cid_parts = array_merge($cid_parts, $contexts); @@ -671,11 +670,10 @@ protected function verifyRenderCache($cid, array $tags, $redirected_cid = NULL) $this->assertTrue(isset($cache_entry->data['#cache_redirect']), 'Render cache entry is a redirect.'); // Verify that the cache redirect points to the expected CID. $redirect_cache_metadata = $cache_entry->data['#cache']; - $cache_keys = array_merge( + $actual_redirection_cid = $this->createCacheId( $redirect_cache_metadata['keys'], - \Drupal::service('cache_contexts')->convertTokensToKeys($redirect_cache_metadata['contexts']) + $redirect_cache_metadata['contexts'] ); - $actual_redirection_cid = implode(':', $cache_keys); $this->assertIdentical($redirected_cid, $actual_redirection_cid); // Finally, verify that the redirected CID exists and has the same cache // tags. diff --git a/core/tests/Drupal/Tests/Core/Cache/CacheContextsTest.php b/core/tests/Drupal/Tests/Core/Cache/CacheContextsTest.php index 8a3e010..1563a6d 100644 --- a/core/tests/Drupal/Tests/Core/Cache/CacheContextsTest.php +++ b/core/tests/Drupal/Tests/Core/Cache/CacheContextsTest.php @@ -33,9 +33,9 @@ public function testConvertTokensToKeys() { ]); $expected = [ - 'bar', 'baz.cnenzrgreN', 'baz.cnenzrgreO', + 'bar', ]; $this->assertEquals($expected, $new_keys); }