diff --git a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php index 1a0741d28340e5299c329baa078f58682f56673a..c8b07ea1e08b30d59470d9a8d553377d31b40041 100644 --- a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php +++ b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php @@ -2112,6 +2112,7 @@ public function render() { // Assigned by reference so anything added in $element['#attached'] will // be available on the view. '#attached' => &$this->view->element['#attached'], + '#cache' => &$this->view->element['#cache'], ); $this->applyDisplayCacheabilityMetadata($this->view->element); diff --git a/core/modules/views/tests/modules/views_test_data/src/Plugin/views/argument_default/ArgumentDefaultTest.php b/core/modules/views/tests/modules/views_test_data/src/Plugin/views/argument_default/ArgumentDefaultTest.php index 6f35ba48b713c1f7f652d2447c7e73d210dc5039..b2ad514f36eefa863b824f0047bcbbdd77197455 100644 --- a/core/modules/views/tests/modules/views_test_data/src/Plugin/views/argument_default/ArgumentDefaultTest.php +++ b/core/modules/views/tests/modules/views_test_data/src/Plugin/views/argument_default/ArgumentDefaultTest.php @@ -28,6 +28,7 @@ protected function defineOptions() { * {@inheritdoc} */ public function getArgument() { + $this->view->element['#cache']['tags'][] = 'example_tag'; return $this->options['value']; } diff --git a/core/modules/views/tests/src/Kernel/Plugin/CacheTest.php b/core/modules/views/tests/src/Kernel/Plugin/CacheTest.php index 31805d8d87c68a118f07db35f5c47fa0c9796413..e1328d767e08b8de5f92420836af91b488810ee0 100644 --- a/core/modules/views/tests/src/Kernel/Plugin/CacheTest.php +++ b/core/modules/views/tests/src/Kernel/Plugin/CacheTest.php @@ -383,4 +383,30 @@ public function testCacheContextIntegration() { $this->assertIdenticalResultset($view, [['name' => 'Paul']], $map); } + /** + * Tests that cacheability metadata is carried over from argument defaults. + */ + public function testArgumentDefaultCache() { + $view = Views::getView('test_view'); + + // Add a new argument and set the test plugin for the argument_default. + $options = array( + 'default_argument_type' => 'argument_default_test', + 'default_argument_options' => array( + 'value' => 'John' + ), + 'default_action' => 'default' + ); + $view->addHandler('default', 'argument', 'views_test_data', 'name', $options); + $view->initHandlers(); + + $output = $view->preview(); + + /** @var \Drupal\Core\Render\RendererInterface $renderer */ + $renderer = \Drupal::service('renderer'); + + $renderer->renderPlain($output); + $this->assertEquals(['config:views.view.test_view', 'example_tag'], $output['#cache']['tags']); + } + }