Skip to content
Snippets Groups Projects
Unverified Commit 26a5a2ab authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2959316 by dww, Lendude, dawehner: Views argument validators that...

Issue #2959316 by dww, Lendude, dawehner: Views argument validators that modify argument values aren't reflected in token replacement
parent 76dcd7c2
No related branches found
No related tags found
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
...@@ -1096,7 +1096,8 @@ protected function _buildArguments() { ...@@ -1096,7 +1096,8 @@ protected function _buildArguments() {
$argument->is_default = TRUE; $argument->is_default = TRUE;
} }
// Set the argument, which will also validate that the argument can be set. // Set the argument, which ensures that the argument is valid and
// possibly transforms the value.
if (!$argument->setArgument($arg)) { if (!$argument->setArgument($arg)) {
$status = $argument->validateFail($arg); $status = $argument->validateFail($arg);
break; break;
...@@ -1110,9 +1111,11 @@ protected function _buildArguments() { ...@@ -1110,9 +1111,11 @@ protected function _buildArguments() {
$argument->query($this->display_handler->useGroupBy()); $argument->query($this->display_handler->useGroupBy());
} }
// Add this argument's substitution // Add this argument's substitution.
$substitutions["{{ arguments.$id }}"] = $arg_title; $substitutions["{{ arguments.$id }}"] = $arg_title;
$substitutions["{{ raw_arguments.$id }}"] = strip_tags(Html::decodeEntities($arg)); // Since argument validator plugins can potentially transform the value,
// use whatever value the argument handler now has, not the raw value.
$substitutions["{{ raw_arguments.$id }}"] = strip_tags(Html::decodeEntities($argument->getValue()));
// Test to see if we should use this argument's title // Test to see if we should use this argument's title
if (!empty($argument->options['title_enable']) && !empty($argument->options['title'])) { if (!empty($argument->options['title_enable']) && !empty($argument->options['title'])) {
......
...@@ -37,6 +37,10 @@ protected function defineOptions() { ...@@ -37,6 +37,10 @@ protected function defineOptions() {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function validateArgument($arg) { public function validateArgument($arg) {
if ($arg === 'this value should be replaced') {
$this->argument->argument = 'this value is replaced!';
return TRUE;
}
return $arg == $this->options['test_value']; return $arg == $this->options['test_value'];
} }
......
...@@ -38,7 +38,7 @@ class ViewExecutableTest extends ViewsKernelTestBase { ...@@ -38,7 +38,7 @@ class ViewExecutableTest extends ViewsKernelTestBase {
* *
* @var array * @var array
*/ */
public static $testViews = ['test_destroy', 'test_executable_displays']; public static $testViews = ['test_destroy', 'test_executable_displays', 'test_argument_dependency'];
/** /**
* Properties that should be stored in the configuration. * Properties that should be stored in the configuration.
...@@ -525,4 +525,19 @@ public function testSerialization() { ...@@ -525,4 +525,19 @@ public function testSerialization() {
$this->assertEquals($nid_definition_before->getPropertyDefinitions(), $nid_definition_after->getPropertyDefinitions()); $this->assertEquals($nid_definition_before->getPropertyDefinitions(), $nid_definition_after->getPropertyDefinitions());
} }
/**
* Tests if argument overrides by validators are propagated to tokens.
*/
public function testArgumentValidatorValueOverride() {
$view = Views::getView('test_argument_dependency');
$view->setDisplay('page_1');
$view->setArguments(['1', 'this value should be replaced']);
$view->execute();
$expected = [
'{{ arguments.uid }}' => 'this value is replaced!',
'{{ raw_arguments.uid }}' => 'this value is replaced!',
];
$this->assertEquals($expected, $view->build_info['substitutions']);
}
} }
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