Grouped exposed taxonomy term filters does not work when input from user is an array.

Created on 3 May 2023, over 1 year ago
Updated 30 April 2024, 7 months ago

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;
      }
    }
๐Ÿ› Bug report
Status

Needs work

Version

11.0 ๐Ÿ”ฅ

Component
Taxonomyย  โ†’

Last updated 4 days ago

  • Maintained by
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States @xjm
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom @catch
Created by

๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom somersoft

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024