Problem/Motivation

When you first check the 'specify validation criteria' and choose a validation criteria for a contextual filter and later you uncheck the box 'specify validation criteria' it still uses this validation.

To reproduce this error:

  • Go to a view and add a contextual filter
  • Select 'specify validation criteria'
  • Choose a validator that doesn't validate (e.g. Comment) and choose an Action to take if filter value does not validate (e.g. Display "Access Denied")
  • Uncheck 'specify validation criteria'
  • Save the view
  • Go to the page/block with the view and you'll see "Access Denied" even though you unchecked the 'specify validation criteria'

Proposed resolution

When you uncheck the 'specify validation criteria', reset the validator to 'basic validation' and if the 'specify validation criteria' is not checked do only a basic validation.

Comments

dawehner’s picture

Issue tags: +Needs tests

@JinX-Be
Thank you for reporting this issue!

Do you want to give it a try in fixing it?

JinX-Be’s picture

@dawehner
Ok, I'll give it a go.

JinX-Be’s picture

Double post sorry

JinX-Be’s picture

JinX-Be’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 4: validation-criteria-contextual-filter-2468851-4.patch, failed testing.

JinX-Be’s picture

Assigned: Unassigned » JinX-Be
Status: Needs work » Needs review
StatusFileSize
new2.29 KB
new3.13 KB

Changed the code and tested locally.
Had to change one of the tests so that specify validation was true where there was a validator set (as mentioned in this bug).

JinX-Be’s picture

Changed the patch.
Now I don't set the basic validation to none when you save the view, but in the rendering.
So if you uncheck the 'specify validation criteria' and afterwards you check it again, your choice is still saved.

Status: Needs review » Needs work

The last submitted patch, 8: validation-criteria-contextual-filter-2468851-8.patch, failed testing.

The last submitted patch, 8: validation-criteria-contextual-filter-2468851-8.patch, failed testing.

upchuk’s picture

Status: Needs work » Needs review
StatusFileSize
new1.01 KB
new952 bytes

Let's see if this fixes the errors.

upchuk’s picture

Assigned: JinX-Be » Unassigned

Unassigning Jinx-BE since he is having connection issues and can't do it himself :)

geertvd’s picture

StatusFileSize
new3.87 KB
new4.75 KB
new4.68 KB
+++ b/core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php
@@ -1079,6 +1079,14 @@ public function getPlugin($type = 'argument_default', $name = NULL) {
+        if (isset($this->options['specify_validation']) && $this->options['specify_validation'] === 0) {

$this->options['specify_validation'] is supposed to be a boolean, I never really passed that if statement. So changed it to use empty() instead.

In addition I found some test views that didn't include the specify_validation option in their yml file, that seems wrong since those views did have a validation option but specify_validation would default to FALSE.

I also added test coverage.

The last submitted patch, 13: 2468851-13-test.patch, failed testing.

The last submitted patch, 13: 2468851-13-test.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 13: 2468851-13-complete.patch, failed testing.

The last submitted patch, 13: 2468851-13-complete.patch, failed testing.

geertvd’s picture

Status: Needs work » Needs review
StatusFileSize
new762 bytes
new5.5 KB

Missed one, some of these test views are really weird.

upchuk’s picture

Issue tags: +Barcelona2015

After speaking to @dawener, we should take care of this at the submit level. When the argument options are submitted, we reset the validate options if the checkbox is unchecked.

Let's see if any tests break...and we also need to write tests for this.

The patch is small and started from scratch.

upchuk’s picture

StatusFileSize
new901 bytes

And the patch...

dawehner’s picture

Yeah that approach is sooo much better, IMHO, but yeah, as you know, westill need some testcoverage.

upchuk’s picture

StatusFileSize
new2.52 KB

Here's a test patch i've been working on...though I can't seem to get it working right at the end..the second postForm doesn't seem to save the changes in the handler and view..

Status: Needs review » Needs work

The last submitted patch, 22: 2468851-test-only-22.patch, failed testing.

The last submitted patch, 22: 2468851-test-only-22.patch, failed testing.

geertvd’s picture

Status: Needs work » Needs review
StatusFileSize
new2.47 KB
new3.35 KB
new1.63 KB

Just using a boolean there works better for me.

The last submitted patch, 25: 2468851-25-test.patch, failed testing.

The last submitted patch, 25: 2468851-25-test.patch, failed testing.

lendude’s picture

Status: Needs review » Needs work
Issue tags: -Needs tests

Manually tested this. Followed the steps to reproduce and the issue still exists. After applying the patch and resaving the argument, the issue is fixed.

Little bit of nitpicking, looks good to me otherwise. And we have tests, yay!

+++ b/core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php
@@ -459,6 +459,12 @@ public function submitOptionsForm(&$form, FormStateInterface $form_state) {
+    // If the 'specify validation' checkbox is checked, reset the validation

+++ b/core/modules/views_ui/src/Tests/ArgumentValidatorTest.php
@@ -0,0 +1,63 @@
+   * Tests the Specify Validation functionality.

It's the 'Specify validation criteria' checkbox. And it should be 'is not checked'.

+++ b/core/modules/views_ui/src/Tests/ArgumentValidatorTest.php
@@ -0,0 +1,63 @@
+   * Tests the Specify Validation functionality.

Bit misleading, it doesn't test the actual functionality, it only tests setting the options. But since it's an UI test, that may be inferred.

+++ b/core/modules/views_ui/src/Tests/ArgumentValidatorTest.php
@@ -0,0 +1,63 @@
+    // Uncheck the 'specify validation' checkbox and expect the validation type

See 1, should be the 'Specify validation criteria' checkbox

dawehner’s picture

+++ b/core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php
@@ -459,6 +459,12 @@ public function submitOptionsForm(&$form, FormStateInterface $form_state) {
+    // If the 'specify validation' checkbox is checked, reset the validation
+    // options.
+    if (empty($option_values['specify_validation'])) {
+      $option_values['validate']['type'] = 'none';
+    }

Should we also truncate the validation options?

upchuk’s picture

Assigned: Unassigned » upchuk
upchuk’s picture

Assigned: upchuk » Unassigned
Status: Needs work » Needs review
StatusFileSize
new2.3 KB
new3.51 KB

Addressed #28 and #29.

Status: Needs review » Needs work

The last submitted patch, 31: 2468851-31.patch, failed testing.

upchuk’s picture

Status: Needs work » Needs review
StatusFileSize
new746 bytes
new3.51 KB

Here we go. This should fix it.

dawehner’s picture

+++ b/core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php
@@ -459,6 +459,14 @@ public function submitOptionsForm(&$form, FormStateInterface $form_state) {
+      $option_values['validate']['options'] = ['none' => []];

Maybe adding a quick comment why this is needed would be nice!

  1. +++ b/core/modules/views_ui/src/Tests/ArgumentValidatorTest.php
    @@ -0,0 +1,63 @@
    +   *
    +   * @throws \Exception
    

    Seems pointless here to add it

  2. +++ b/core/modules/views_ui/src/Tests/ArgumentValidatorTest.php
    @@ -0,0 +1,63 @@
    +  private function saveArgumentHandlerWithValidationOptions($specify_validation) {
    

    let's just use protected, its how we roll

The last submitted patch, 31: 2468851-31.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 33: 2468851-33.patch, failed testing.

upchuk’s picture

Status: Needs work » Needs review
StatusFileSize
new1.56 KB
new3.59 KB

Here we go. The Exception thing was added by my PHPStorm :P

lendude’s picture

Status: Needs review » Reviewed & tested by the community

All issues raised so far seem addressed, looks good to me.

  • webchick committed 071d26a on
    Issue #2468851 by Upchuk, geertvd, JinX-Be, dawehner, Lendude:...
webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 8.0.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.