Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Warning: Invalid argument supplied for foreach() in Drupal\taxonomy\Plugin\views\filter\TaxonomyIndexTid->validateExposed()
Step to reproduce:
- Add a vocabulary, but don't add terms
- Make a content View
- add Content: Has taxonomy term filter
- Expose this filter
- In Settings target your empty vocabulary
- Chose Selection type: autocomplete
Proposed resolution
Check it :)
Remaining tasks
User interface changes
API changes
Comment | File | Size | Author |
---|---|---|---|
#21 | taxo_filter-Do_not_loop_on_ALL-2461017-21-8.x.patch | 832 bytes | DuneBL |
#15 | interdiff-2461017-13-15.txt | 2.32 KB | aerozeppelin |
#15 | 2461017-15.patch | 4.59 KB | aerozeppelin |
#13 | interdiff-2461017-11-13.txt | 3.44 KB | aerozeppelin |
#13 | 2461017-13.patch | 4.58 KB | aerozeppelin |
Comments
Comment #1
BerdirAnd here's a patch.
Comment #2
jibranComment #3
dawehnerSeems legit!
Comment #4
LendudeThis happens when you use the autocomplete option targeting an empty vocabulary.
Step to reproduce:
- Add a vocabulary, but don't add terms
- Make a content View
- add Content: Has taxonomy term filter
- Expose this filter
- In Settings target your empty vocabulary
- Chose Selection type: autocomplete
results in
Warning: Invalid argument supplied for foreach() in Drupal\taxonomy\Plugin\views\filter\TaxonomyIndexTid->validateExposed()
Needs tests, so back to 'needs work'.
Comment #5
aerozeppelin CreditAttribution: aerozeppelin commentedTests for #1.
Comment #8
BerdirLooks like the patch fails, so needs work.
Comment #9
aerozeppelin CreditAttribution: aerozeppelin commentedAn attempt to fix errors from #5.
Comment #10
LendudeWe got tests, nice!
Couple of things:
method is missing a docblock, but maybe the tests can just be added to testExposedFilter(), no real need to bootstap Drupal all over again for this.
I don't think there is any need to go into the dblog to check the error. The test will fail just fine if a PHP error is thrown.
The test does need some more assertions I think. If you add it to testExposedFilter() maybe just make sure the View result is empty, since no nodes will have tags from the empty vocabulary.
This is not needed when you change the Views config via PostForm.
Comment #11
aerozeppelin CreditAttribution: aerozeppelin commented@Lendude thank you for reviewing my patch and the feedback.
I made changes as per #10. Let me know if they are acceptable.
Comment #12
Lendude@aerozeppelin looking much better, couple of little things:
not needed.
some documentation/comment as to what is going to be tested would be nice.
Commented out line should be removed.
Why the 'Apply'? Don't think that is needed here right?
Comment #13
aerozeppelin CreditAttribution: aerozeppelin commented@Lendude thanks again for your feedback. :D I've made some changes as per #12.
I agree, that line appears to be redundant.
Comment #14
Lendude@aerozeppelin nice clean up, couple of little things left, then this is good to go for me:
all comments need full stop/period/. at the end.
remove the extra white space/indents and add a comma at the end of the last item in the array. Something along these lines:
Comment #15
aerozeppelin CreditAttribution: aerozeppelin commented@Lendude here you go. Changes as per #14.
Comment #16
Lendude@aerozeppelin nice! We got tests and a fix.
Comment #17
catchCommitted/pushed to 8.1.x and cherry-picked to 8.0.x. Thanks!
Comment #21
DuneBLThere is still a small issue with this patch: if it is a grouped filter with 'All' as default value, it will try to loop around a string... which is bad.
Please review the attached patch
Comment #22
gnugetPlease open a new issue and upload your patch there.
This one has been closed for two years.
Thanks!