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()

Issue fork drupal-3257433

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:

Comments

jeetmail72 created an issue. See original summary.

jeetmail72’s picture

Status: Active » Needs review
StatusFileSize
new802 bytes

I 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.

jeetmail72’s picture

StatusFileSize
new782 bytes

The attached
views-entity-reference-filter-3257433.patch file fixed the issue when using the EntityReference field as exposed filter with Better Exposed Filter.

quietone’s picture

Status: Needs review » Postponed (maintainer needs more info)

@jeetmail72, Drupal 8 is EOL. Did you mean to select Drupal 8.9.x or another version?

gngn’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new770 bytes

#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.

jeetmail72’s picture

Title: Warning: Invalid argument supplied for foreach() with Better Exposed Filter & Grouped Filter » Warning: Invalid argument supplied for foreach() with Better Exposed Filter & Grouped Filter 8.9.x
Issue summary: View changes
jeetmail72’s picture

@quietone I am talking about Drupal 8.9.x

cilefen’s picture

Drupal 8 is not going to be released any more. Is the bug reproducible on Drupal 9?

quietone’s picture

Status: Needs review » Postponed (maintainer needs more info)
Issue tags: +Bug Smash Initiative

Since 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!

gngn’s picture

We first encountered the bug with drupal 9.3.0 (as mentioned in #5).

eduardo morales alberti’s picture

This happened also to us on Drupal 9.3.0

eduardo morales alberti’s picture

Title: Warning: Invalid argument supplied for foreach() with Better Exposed Filter & Grouped Filter 8.9.x » Warning: Invalid argument supplied for foreach() with Better Exposed Filter & Grouped Filter
Version: 8.9.x-dev » 9.3.x-dev

Maybe 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.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Version: 9.5.x-dev » 11.x-dev

Should this be reopened based on previous comments? Anyone able to replicate on D10?

pameeela’s picture

I'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?

pameeela’s picture

Assigned: jeetmail72 » Unassigned
Status: Postponed (maintainer needs more info) » Active

Discussed in Slack, will create an MR with a modified fix.

pameeela’s picture

Status: Active » Needs review

Created 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.

pameeela credited chx.

pameeela’s picture

Crediting @chx for Slack participation.

needs-review-queue-bot’s picture

Status: Needs review » Needs work

The 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.)

pameeela’s picture

Status: Needs work » Needs review
Issue tags: -Needs steps to reproduce

Hiding patches

smustgrave’s picture

Status: Needs review » Needs work

Wondering if we the summary could be updated with proposed solution from the slack channel.

pameeela’s picture

Issue summary: View changes
Status: Needs work » Needs review

The MR is pretty straightforward but I added a line about the proposed resolution. Not sure if that is what you mean @smustgrave?

smustgrave’s picture

Yup just because not everyone is in slack so any discussion there isn’t known

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Meant to mark this a few days ago.

quietone’s picture

Title: Warning: Invalid argument supplied for foreach() with Better Exposed Filter & Grouped Filter » When validating the term id filter allow an identifier that are is not an array

I 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.

quietone’s picture

Title: When validating the term id filter allow an identifier that are is not an array » Validate that the term ID value is an array in taxonomy_index_tid views filter

Better title, I hope.

larowlan’s picture

Status: Reviewed & tested by the community » Postponed (maintainer needs more info)

I'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 InOperator

In 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?

smustgrave’s picture

Status: Postponed (maintainer needs more info) » Closed (won't fix)

If we can fix in BEF I'm fine with that.