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
Branches
Tags
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -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);
......
......@@ -28,6 +28,7 @@ protected function defineOptions() {
* {@inheritdoc}
*/
public function getArgument() {
$this->view->element['#cache']['tags'][] = 'example_tag';
return $this->options['value'];
}
......
......@@ -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']);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment