Commit 071d26a1 authored by webchick's avatar webchick

Issue #2468851 by Upchuk, geertvd, JinX-Be, dawehner, Lendude: Validation...

Issue #2468851 by Upchuk, geertvd, JinX-Be, dawehner, Lendude: Validation criteria of contextual filter stays active after unchecking 'Specify validation criteria'
parent 7b1ad46f
......@@ -460,6 +460,16 @@ public function submitOptionsForm(&$form, FormStateInterface $form_state) {
$option_values['summary_options'] = $options;
}
// If the 'Specify validation criteria' checkbox is not checked, reset the
// validation options.
if (empty($option_values['specify_validation'])) {
$option_values['validate']['type'] = 'none';
// We need to keep the empty array of options for the 'None' plugin as
// it will be needed later.
$option_values['validate']['options'] = ['none' => []];
$option_values['validate']['fail'] = 'not found';
}
$sanitized_id = $option_values['validate']['type'];
// Correct ID for js sanitized version.
$option_values['validate']['type'] = $validate_id = static::decodeValidatorId($sanitized_id);
......
<?php
/**
* @file
* Contains \Drupal\views_ui\Tests\ArgumentValidatorTest.
*/
namespace Drupal\views_ui\Tests;
use Drupal\views\Views;
/**
* Tests the Argument validator through the UI.
*
* @group views_ui
*/
class ArgumentValidatorTest extends UITestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_argument');
/**
* Tests the 'Specify validation criteria' checkbox functionality.
*/
public function testSpecifyValidation() {
// Specify a validation based on Node for the 'id' argument on the default
// display and assert that this works.
$this->saveArgumentHandlerWithValidationOptions(TRUE);
$view = Views::getView('test_argument');
$handler = $view->getHandler('default', 'argument', 'id');
$this->assertTrue($handler['specify_validation'], 'Validation for this argument has been turned on.');
$this->assertEqual('entity:node', $handler['validate']['type'], 'Validation for the argument is based on the node.');
// Uncheck the 'Specify validation criteria' checkbox and expect the
// validation type to be reset back to 'none'.
$this->saveArgumentHandlerWithValidationOptions(FALSE);
$view = Views::getView('test_argument');
$handler = $view->getHandler('default', 'argument', 'id');
$this->assertFalse($handler['specify_validation'], 'Validation for this argument has been turned off.');
$this->assertEqual('none', $handler['validate']['type'], 'Validation for the argument has been reverted to Basic Validation.');
}
/**
* Saves the test_argument view with changes made to the argument handler
* both with and without specify_validation turned on.
*
* @param boolean $specify_validation
*/
protected function saveArgumentHandlerWithValidationOptions($specify_validation) {
$options = array(
'options[validate][type]' => 'entity---node',
'options[specify_validation]' => $specify_validation,
);
$this->drupalPostForm('admin/structure/views/nojs/handler/test_argument/default/argument/id', $options, t('Apply'));
$this->drupalPostForm('admin/structure/views/view/test_argument', array(), t('Save'));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment