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
Comment | File | Size | Author |
---|---|---|---|
#20 | test-only-2662978-19-1.patch | 11.79 KB | mohit_aghera |
#2 | 2662978-2.patch | 818 bytes | EclipseGc |
Issue fork drupal-2662978
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:
Comments
Comment #2
EclipseGc CreditAttribution: EclipseGc commentedCODE!
Comment #3
EclipseGc CreditAttribution: EclipseGc commentedlet's see what testbot says.
Comment #5
arknoll CreditAttribution: arknoll commentedThis works for us. Allows ctools views to work.
Comment #6
alexpottIt'd be good to have a failing test - which passes once the patch is applied.
Comment #7
dawehnerDid someone the research to see when this was included the first time? IMHO this is important to understand why the code existed before.
Comment #15
pyrello CreditAttribution: pyrello commentedIf 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.
Comment #16
MatroskeenAh, 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!
Comment #17
MatroskeenAdding duplicates after some digging through issues queue.
Comment #18
pyrello CreditAttribution: pyrello commentedTo 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.
Comment #20
mohit_aghera CreditAttribution: mohit_aghera at QED42 commentedAdding test-only patch for the failures.
Moving to PR-based approach for the actual patch and test cases.
Comment #23
mohit_aghera CreditAttribution: mohit_aghera at QED42 commentedComment #24
MatroskeenWe'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.
Comment #25
LendudeTransferred credit, so this can be closed as a duplicate, thanks for all the work here!