.../Core/Render/MainContent/SmartCacheHtmlRenderer.php | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/core/lib/Drupal/Core/Render/MainContent/SmartCacheHtmlRenderer.php b/core/lib/Drupal/Core/Render/MainContent/SmartCacheHtmlRenderer.php index 3806958..bccd9f6 100644 --- a/core/lib/Drupal/Core/Render/MainContent/SmartCacheHtmlRenderer.php +++ b/core/lib/Drupal/Core/Render/MainContent/SmartCacheHtmlRenderer.php @@ -58,19 +58,18 @@ class SmartCacheHtmlRenderer extends HtmlRenderer { * The module handler. * @param \Drupal\Core\Render\RendererInterface $renderer * The renderer service. - * @param \Drupal\Core\Routing\RouteMatchInterface $route_match - * The current route match. * @param \Drupal\Core\Cache\CacheContexts $cache_contexts * The cache contexts service. + * @param \Drupal\Core\Routing\RouteMatchInterface $route_match + * The current route match. * @param \Drupal\Core\Cache\CacheBackendInterface $contexts_cache * The Smart Cache contexts cache bin. * @param \Drupal\Core\Cache\CacheBackendInterface $html_cache * The Smart Cache #type => html render array cache bin. */ - public function __construct(TitleResolverInterface $title_resolver, PluginManagerInterface $display_variant_manager, EventDispatcherInterface $event_dispatcher, ModuleHandlerInterface $module_handler, RendererInterface $renderer, RouteMatchInterface $route_match, CacheContexts $cache_contexts, CacheBackendInterface $contexts_cache, CacheBackendInterface $html_cache) { - parent::__construct($title_resolver, $display_variant_manager, $event_dispatcher, $module_handler, $renderer); + public function __construct(TitleResolverInterface $title_resolver, PluginManagerInterface $display_variant_manager, EventDispatcherInterface $event_dispatcher, ModuleHandlerInterface $module_handler, RendererInterface $renderer, CacheContexts $cache_contexts, RouteMatchInterface $route_match, CacheBackendInterface $contexts_cache, CacheBackendInterface $html_cache) { + parent::__construct($title_resolver, $display_variant_manager, $event_dispatcher, $module_handler, $renderer, $cache_contexts); $this->routeMatch = $route_match; - $this->cacheContexts = $cache_contexts; $this->smartContextsCache = $contexts_cache; $this->smartHtmlCache = $html_cache; } @@ -106,14 +105,13 @@ protected function finish(array $html) { $html_cache_tags = []; foreach (Element::children($cacheable_html) as $child) { $cacheable_html[$child] = $this->renderer->getCacheableRenderArray($cacheable_html[$child]); - $cache_contexts = array_unique(array_merge($cache_contexts, $cacheable_html[$child]['#cache']['contexts'])); + $cache_contexts = Cache::mergeContexts($cache_contexts, $cacheable_html[$child]['#cache']['contexts']); $html_cache_tags = Cache::mergeTags($html_cache_tags, $cacheable_html[$child]['#cache']['tags']); } - sort($cache_contexts); // @todo Remove this. Work-around to support the deep-render-array-scanning- // dependent logic bartik_preprocess_html() has: it needs to know about - // the presence or absence of certain regoions. That is similar (but less + // the presence or absence of certain regions. That is similar (but less /// bad) to the evil things one could do with hook_page_alter() in D7. foreach (Element::children($html['page']) as $page_region) { $cacheable_html['page'][$page_region] = ['#preprocess_functions_messing_with_cacheability' => TRUE]; @@ -123,8 +121,7 @@ protected function finish(array $html) { // stored cache contexts and the contexts for this request. if ($cache_contexts !== $stored_cache_contexts) { if (is_array($stored_cache_contexts)) { - $cache_contexts = array_merge($cache_contexts, $stored_cache_contexts); - sort($cache_contexts); + $cache_contexts = Cache::mergeContexts($cache_contexts, $stored_cache_contexts); } $this->smartContextsCache->set($contexts_cid, $cache_contexts); }