core/lib/Drupal/Core/Render/Renderer.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/core/lib/Drupal/Core/Render/Renderer.php b/core/lib/Drupal/Core/Render/Renderer.php index 3521cb5..31d1ebd 100644 --- a/core/lib/Drupal/Core/Render/Renderer.php +++ b/core/lib/Drupal/Core/Render/Renderer.php @@ -166,6 +166,7 @@ protected function doRender(&$elements, $is_root_call = FALSE) { // Try to fetch the prerendered element from cache, run any // #post_render_cache callbacks and return the final markup. + $pre_bubbling_cid = NULL; if (isset($elements['#cache'])) { $cached_element = $this->cacheGet($elements); if ($cached_element !== FALSE) { @@ -191,7 +192,7 @@ protected function doRender(&$elements, $is_root_call = FALSE) { // @see ::cacheGet() // @see ::cacheSet() if ($this->requestStack->getCurrentRequest()->isMethodSafe() && $cid = $this->createCacheID($elements)) { - $elements['#cid_pre_bubbling'] = $cid; + $pre_bubbling_cid = $cid; } } } @@ -357,7 +358,7 @@ protected function doRender(&$elements, $is_root_call = FALSE) { // Cache the processed element if #cache is set, and the metadata necessary // to generate a cache ID is present. if (isset($elements['#cache']) && (isset($elements['#cache']['keys']) || isset($elements['#cache']['cid']))) { - $this->cacheSet($elements); + $this->cacheSet($elements, $pre_bubbling_cid); } // Only when we're in a root (non-recursive) drupal_render() call, @@ -524,13 +525,15 @@ protected function cacheGet(array $elements) { * * @param array $elements * A renderable array. + * @param string|null $pre_bubbling_cid + * The pre-bubbling cache ID. * * @return bool|null * Returns FALSE if no cache item could be created, NULL otherwise. * * @see ::getFromCache() */ - protected function cacheSet(array &$elements) { + protected function cacheSet(array &$elements, $pre_bubbling_cid) { // Form submissions rely on the form being built during the POST request, // and render caching of forms prevents this from happening. // @todo remove the isMethodSafe() check when @@ -554,7 +557,7 @@ protected function cacheSet(array &$elements) { // update redirect if different set of cache contexts. // @see ::doRender() // @see ::cacheGet() - if (isset($elements['#cid_pre_bubbling']) && $elements['#cid_pre_bubbling'] !== $cid) { + if (isset($pre_bubbling_cid) && $pre_bubbling_cid !== $cid) { // The set of cache contexts for this element, including the bubbled ones, // for which we are handling a cache miss. $cache_contexts = $data['#cache']['contexts']; @@ -563,7 +566,7 @@ protected function cacheSet(array &$elements) { // the current redirecting cache item, if any. $stored_cache_contexts = []; $stored_cache_tags = []; - if ($stored_cache_redirect = $cache->get($elements['#cid_pre_bubbling'])) { + if ($stored_cache_redirect = $cache->get($pre_bubbling_cid)) { $stored_cache_contexts = $stored_cache_redirect->data['#cache']['contexts']; $stored_cache_tags = $stored_cache_redirect->data['#cache']['tags']; } @@ -587,7 +590,7 @@ protected function cacheSet(array &$elements) { 'tags' => Cache::mergeTags($stored_cache_tags, $data['#cache']['tags']), ], ]; - $cache->set($elements['#cid_pre_bubbling'], $redirect_data, $expire, $redirect_data['#cache']['tags']); + $cache->set($pre_bubbling_cid, $redirect_data, $expire, $redirect_data['#cache']['tags']); } // Current cache contexts incomplete: this request only uses a subset of