diff --git a/core/modules/views/src/Plugin/Block/ViewsExposedFilterBlock.php b/core/modules/views/src/Plugin/Block/ViewsExposedFilterBlock.php index 09b3662..e255ede 100644 --- a/core/modules/views/src/Plugin/Block/ViewsExposedFilterBlock.php +++ b/core/modules/views/src/Plugin/Block/ViewsExposedFilterBlock.php @@ -24,21 +24,12 @@ class ViewsExposedFilterBlock extends ViewsBlockBase { */ public function build() { $output = $this->view->display_handler->viewExposedFormBlocks(); + $output['#cache']['contexts'] = $this->view->display_handler->getCacheMetadata()->getCacheContexts(); + // Before returning the block output, convert it to a renderable array with // contextual links. $this->addContextualLinks($output, 'exposed_filter'); - // Merge cache contexts for each filter option. - if (!isset($output['#cache']['contexts'])) { - $output['#cache']['contexts'] = []; - } - $contexts = &$output['#cache']['contexts']; - foreach ($this->view->filter as $id => $handler) { - if ($handler->canExpose() && $handler->isExposed()) { - $contexts = Cache::mergeContexts($contexts, $handler->getCacheContexts()); - } - } - return $output; } diff --git a/core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php b/core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php index 5a47cfe..33267b2 100644 --- a/core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php +++ b/core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php @@ -359,6 +359,14 @@ public function getCacheContexts() { } } + // Merge in cache contexts for all exposed filters to prevent display of + // cached forms. + foreach ($this->displayHandler->getHandlers('filter') as $filter_hander) { + if ($filter_hander->isExposed()) { + $contexts = Cache::mergeContexts($contexts, $filter_hander->getCacheContexts()); + } + } + return $contexts; }