Problem/Motivation

\Drupal\taxonomy\Plugin\views\filter\TaxonomyIndexTid::acceptExposedInput takes the value of the filter and resets it to the value in the validated_exposed_input property. This property has to be set in order for the method to even make it as far as the last bit of code that does this, however, \Drupal\views\Plugin\views\filter\FilterPluginBase::acceptExposedInput (which TaxonomyIndexTid will call to by calling to it's parent which calls to the FilterPluginBase method) sets $this->value such:

$value = $input[$this->options['expose']['identifier']];

This will 'unnest' the value that exists in validate_exposed_input and make it actively usable to the form and the query. But these last lines of TaxonomyIndexTid::acceptExposedInput basically undo all this work, and prevents things like form defaults from working properly.

Steps to reproduce

1. Create a content type with a taxonomy reference field;
2. Create a view with content items (I had Block with AJAX enabled);
3. Make a filter by taxonomy field with the following settings:
- exposed;
- grouped;
- optional (not sure if matters);
- widget type - Radios (not sure if matters);
- group option with selected terms;
4. Submit exposed form with selected group -> observe incorrect results;

Proposed resolution

Remove these lines and just return parent::acceptExposedInput. I have yet to see how this code is actually useful.

Eclipse

Issue fork drupal-2662978

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

EclipseGc created an issue. See original summary.

EclipseGc’s picture

EclipseGc’s picture

Status: Active » Needs review

let's see what testbot says.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

arknoll’s picture

Status: Needs review » Reviewed & tested by the community

This works for us. Allows ctools views to work.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

It'd be good to have a failing test - which passes once the patch is applied.

dawehner’s picture

I have yet to see how this code is actually useful.

Did someone the research to see when this was included the first time? IMHO this is important to understand why the code existed before.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

pyrello’s picture

If possible, it would be good to get some guidance on what a test might look like for this, especially if there is an existing example that can be adapted. I'd be interested in adding the test, but I don't have much experience writing them and I'm not sure how to get started.

Matroskeen’s picture

Version: 8.9.x-dev » 9.3.x-dev
Issue summary: View changes
Issue tags: +Bug Smash Initiative

Ah, just spent ~1h trying to figure out what's going in there :(
This is still valid for the latest 9.3.x.

I'm adding steps to reproduce, so it's easier to write a test.

By the way, patch #2 did the trick for me. Thanks for that!

Matroskeen’s picture

pyrello’s picture

To answer to the question posed by dawehner above, the section of code appears to have been brought over from the 7.x-3.x version of views: https://git.drupalcode.org/project/drupal/-/blame/d6f0adbbe3c31684a4bec6.... Its origins prior to that point are a bit more difficult to discern.

I am noticing that this patch seems to render non-grouped term exposed filter non-functional.

It looks like there used to be a work-around for groups, but this doesn't seem to have made it into the version that was ported over to D8: https://git.drupalcode.org/project/views/-/blame/7.x-3.x/modules/taxonom...

This would seem to suggest that https://www.drupal.org/project/drupal/issues/1810148 might be a better way to solve this issue.

mohit_aghera made their first commit to this issue’s fork.

mohit_aghera’s picture

Status: Needs work » Needs review
FileSize
11.79 KB

Adding test-only patch for the failures.
Moving to PR-based approach for the actual patch and test cases.

Status: Needs review » Needs work

The last submitted patch, 20: test-only-2662978-19-1.patch, failed testing. View results

mohit_aghera’s picture

Status: Needs work » Needs review
Matroskeen’s picture

We'll be pushing forward the original task #1810148: Grouped exposed taxonomy term filters do not work because the group key is added to the query and not the taxonomy ID, which is almost 10 years old.

@mohit_aghera thank you so much for the test, I already pushed it there.
I'll ask someone to transfer the issue credit and we'll mark this one as duplicate.

Lendude’s picture

Status: Needs review » Closed (duplicate)

Transferred credit, so this can be closed as a duplicate, thanks for all the work here!