Skip to content
Snippets Groups Projects
Commit 7e506626 authored by Jess's avatar Jess
Browse files

Issue #2853592 by Lendude, dawehner: Cacheability metadata can't be set from...

Issue #2853592 by Lendude, dawehner: Cacheability metadata can't be set from within argument default handlers
parent 818c3fa7
No related branches found
No related tags found
No related merge requests found
...@@ -2112,6 +2112,7 @@ public function render() { ...@@ -2112,6 +2112,7 @@ public function render() {
// Assigned by reference so anything added in $element['#attached'] will // Assigned by reference so anything added in $element['#attached'] will
// be available on the view. // be available on the view.
'#attached' => &$this->view->element['#attached'], '#attached' => &$this->view->element['#attached'],
'#cache' => &$this->view->element['#cache'],
); );
$this->applyDisplayCacheabilityMetadata($this->view->element); $this->applyDisplayCacheabilityMetadata($this->view->element);
......
...@@ -28,6 +28,7 @@ protected function defineOptions() { ...@@ -28,6 +28,7 @@ protected function defineOptions() {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getArgument() { public function getArgument() {
$this->view->element['#cache']['tags'][] = 'example_tag';
return $this->options['value']; return $this->options['value'];
} }
......
...@@ -383,4 +383,30 @@ public function testCacheContextIntegration() { ...@@ -383,4 +383,30 @@ public function testCacheContextIntegration() {
$this->assertIdenticalResultset($view, [['name' => 'Paul']], $map); $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']);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment