Problem/Motivation
View exposed filter displays an error with a term ID multiple select and group filter.
The website encountered an unexpected error. Please try again later.
TypeError: Illegal offset type in isset or empty in Drupal\taxonomy\Plugin\views\filter\TaxonomyIndexTid->validateExposed() (line 366 of core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php).
Drupal\taxonomy\Plugin\views\filter\TaxonomyIndexTid->validateExposed(Array, Object) (Line: 169)
Drupal\views\Form\ViewsExposedForm->validateForm(Array, Object)
Steps to reproduce
Create view follow steps below:
- Node type Article have reference field to the taxonomy term "Tags"
- Create a view to show Article
- Add a Tid filter
- Select Grouped filters
- Allow multiple selections
- Input group label and select the value in the group table
Test view I exported: views.view_.test_exposed_form_tid_grouped_filter.yml
Screen record: https://www.youtube.com/watch?v=FQ1nnpWHkko
Proposed resolution
Detect if an array is returned if so:
- filter out any empty values, and check that there is something in the array.
- extract the equivalent value from the group_info -> group_items $input and concatenate into $this->validated_exposed_input
core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php:348
if ($this->options['is_grouped']) {
if (is_array($input)) {
$filtered_inputs = array_filter($input);
if ($filtered_inputs) {
$values = [];
foreach ($filtered_inputs as $filtered_input) {
$values += $this->options['group_info']['group_items'][$filtered_input]['value'];
}
$this->validated_exposed_input = array_values($values);
return;
}
}
elseif (isset($this->options['group_info']['group_items'][$input])) {
$this->validated_exposed_input = $this->options['group_info']['group_items'][$input]['value'];
return;
}
}
| Comment | File | Size | Author |
|---|
Issue fork drupal-3357973
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
somersoft commentedComment #3
smustgrave commentedIssue summary should be updated with proposed solution. "Apply patch" doesn't count unfortunately.
Also as a bug it will need a test case
Moving version to 10.1 as 9.4 is only under security coverage.
Comment #4
luke.stewart commentedSummarised patch and added to the proposed solution. Removed the needs issue summary update.
Comment #6
phthlaap commentedComment #10
phthlaap commentedComment #11
phthlaap commentedComment #12
phthlaap commentedComment #13
phthlaap commentedComment #14
smustgrave commentedRan test-only feature and showed you do get the WSOD https://git.drupalcode.org/issue/drupal-3357973/-/jobs/1383399 removing that tag
Manually testing following the steps and confirmed the issue
Just FYI, not a problem, but don't need to include the code in the proposed solution. Explaining the solution usually work. Again not a problem if you do just mentioning.
LGTM
Comment #15
quietone commentedSo, we have updates to the issue summary. Thank you!
The test-only tests have been run and there has been manually tested. That is all great. But what is missing is a code review. I left some notes in the MR.
Comment #17
weddled commentedI am having his issue with Drupal 10.2.5. Add a filter to a views and use taxonomy term select expose filter, grouped, allow multiples (vocabulary). Get the error: TypeError: Illegal offset type in isset or empty in Drupal\taxonomy\Plugin\views\filter\TaxonomyIndexTid->validateExposed() (line 349 of /opt/drupal/web/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php). Any updates on this?
Comment #18
pcambraWhen saving some of these views, there's an error caused by trusted config
Comment #19
pcambraI think this is affecting other filters that can be grouped
Comment #20
pcambraComment #21
pcambraComment #22
pcambraI'm seeing a lot of duplication for the same issue
Comment #23
pcambraI've removed the commit from #21 as this issue is already handled in #2920039: Views' User Name exposed group filter validation
However, not sure which one is the best option to keep as this is dupe from #2576927: Grouped exposed taxonomy filter fails validation for autocomplete widget
Comment #24
baluertl