Problem/Motivation
I am getting the following error when used Better Exposed Filter and Grouped Filter with checkbox. Warning: Invalid argument supplied for foreach() in Drupal\taxonomy\Plugin\views\filter\TaxonomyIndexTid->validateExposed() (line 365 of core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php)
Steps to reproduce
Create a view and add an exposed filter (Term field or EntityReference Field) with Grouped Filter option and set Better Exposed Filter for the same field as Single On/Off Checkbox as screenshot attached. Now you will see the checkbox option on the page and when you select the checkbox and submit the form, will cause the error.
Proposed resolution
Check that $values is an array before passing it to the foreach()
| Comment | File | Size | Author |
|---|---|---|---|
| Employee (Content) _ Drupal 9.2.7.png | 36.21 KB | jeetmail72 | |
| Employee (Content) _ Drupal 9.2.7 (1).png | 113.49 KB | jeetmail72 |
Issue fork drupal-3257433
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:
- 3257433-warning-invalid-argument
changes, plain diff MR !8725
Comments
Comment #2
jeetmail72I applied the attached patch and issue fixed.
The attached
taxonomy-views-plugin-filter-3257433.patch file fixed the issue when using the Taxonomy Term field as exposed filter with Better Exposed Filter.
Comment #3
jeetmail72The attached
views-entity-reference-filter-3257433.patch file fixed the issue when using the EntityReference field as exposed filter with Better Exposed Filter.
Comment #4
quietone commented@jeetmail72, Drupal 8 is EOL. Did you mean to select Drupal 8.9.x or another version?
Comment #5
gngn commented#2 fixes the PHP warning we encountered in our system.
But we couldn't apply it with composer - I think 'docroot/' is wrong in the paths.
Changing 'a/docroot/core/modules/...' to 'a/core/modules/' and so on did the trick for us.
Attached is the same as #2 without 'docroot/' in the paths.
@quietone We could apply the attached version to core 9.3.0.
Gave us:
"Hunk #1 succeeded at 362 (offset 5 lines)."
and worked.
Comment #6
jeetmail72Comment #7
jeetmail72@quietone I am talking about Drupal 8.9.x
Comment #8
cilefen commentedDrupal 8 is not going to be released any more. Is the bug reproducible on Drupal 9?
Comment #9
quietone commentedSince we need more information to move forward with this issue, I am setting the status to Postponed (maintainer needs more info). If we don't receive information that this is a problem on a supported version of Drupal it may be closed after three months.
Thanks!
Comment #10
gngn commentedWe first encountered the bug with drupal 9.3.0 (as mentioned in #5).
Comment #11
eduardo morales albertiThis happened also to us on Drupal 9.3.0
Comment #12
eduardo morales albertiMaybe is something that should be fixed on the lower level, but at a higher level and as a workaround to avoid the warning, patch #5 works for drupal 9.3.
We do not have Better Exposed filter installed on our Drupal.
We are using Views data export, the main view has a taxonomy reference field as select, but the export view has it as a autocomplete, when I change both to dropdown the error disappeared.
Comment #15
smustgrave commentedShould this be reopened based on previous comments? Anyone able to replicate on D10?
Comment #16
pameeela commentedI've tried to reproduce using the info in the IS on 10.2 and no luck, not seeing any warnings with this config. The steps in #12 are not clear enough to test them. If this is still occurring could someone please update the issue summary with specific steps to reproduce it?
Comment #17
pameeela commentedDiscussed in Slack, will create an MR with a modified fix.
Comment #19
pameeela commentedCreated an MR to add a check that $values is an array. There is no test here because it would be very difficult to come up with one, so hoping it qualifies for an exemption given both the simplicity of the fix and the fact that it is only resolving a warning.
Comment #21
pameeela commentedCrediting @chx for Slack participation.
Comment #22
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue.
While you are making the above changes, we recommend that you convert this patch to a merge request. Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)
Comment #23
pameeela commentedHiding patches
Comment #24
smustgrave commentedWondering if we the summary could be updated with proposed solution from the slack channel.
Comment #25
pameeela commentedThe MR is pretty straightforward but I added a line about the proposed resolution. Not sure if that is what you mean @smustgrave?
Comment #26
smustgrave commentedYup just because not everyone is in slack so any discussion there isn’t known
Comment #27
smustgrave commentedMeant to mark this a few days ago.
Comment #28
quietone commentedI read the issue summary, comments and the MR. I see there are no tests, but that is explained in #19. I have not evaluated that with the testing heuristics. A reminder to us all to summary Slack discussions in a comment. There is no indication here why $value is not an array or if that is really a contrib problem.
Also, trying for a better title. Leaving at RTBC.
Comment #29
quietone commentedBetter title, I hope.
Comment #30
larowlanI'm inclined to mark this won't fix as it feels that exposing a single checkbox for a views filter that expects multiple values is not correct.
i.e. I don't think BEF should allow using a single checkbox for any filter plugin that extends from
InOperatorIn addition I don't think the fix is correct. Rather than casting a single value to an array, its just ignoring the value and hence the submitted value will not be seen. So I think that would mean the filter doesn't work at all.
As maintainer of BEF @smustgrave is there scope for it to prevent assigning a single-value field to a multi-value filter?
Comment #31
smustgrave commentedIf we can fix in BEF I'm fine with that.