An error occurs in Views when attempting to add an exposed filter by ID with the 'Allow multiple selections' option enabled.

Created on 4 January 2019, about 6 years ago
Updated 19 June 2024, 7 months ago

Problem/Motivation

Generically, the issue seems to be no graceful failure when form builder expects an array and gets a string.

Steps to Reproduce: method 1

  • Create a page view for Content with url: /test-filter-grouped-id
  • Add a Content ID filter
  • Select Expose this filter to visitors, to allow them to change it
  • Select Grouped filters, see my screenshot โ†’
  • Select Allow multiple selections
  • In the group table, add Group 1 is equal to 1
  • In the group table, add Group 2 is equal to 2
  • In the group table, add Group 3 is equal to 3
  • Save view
  • Goto page /test-filter-grouped-id?nid=1 the issue will happen

Steps to Reproduce: method 2

  • Create a view.
  • Add a filter (e.g. a taxonomy with filter identifier "tid"), make it exposed; configure the filter to "Allow multiple selections"
  • Make a page display (e.g. "/test_view") to allow easy access to the filter query params. Save and navigate to the page.
  • Use the exposed filter and note that the URL becomes something like "test_view?tid[N]=N" where N is the id of your taxonomy term.
  • Change the query parameter to be something like "?tid=foo".
    Note that you get a fatal error ""

This error is identical to that mentioned in , summarized here:

When Layout builder is active and I try to save a Content type "The website encountered an unexpected error. Please try again later." turns up and I have the below errors. What could this be?
PHP 7.2.13-1+0~20181207100540.13+stretch~1.gbpf57305
DB 5.5.5-10.1.37-MariaDB-0+deb9u1
Error: Cannot create references to/from string offsets i Drupal\Component\Utility\NestedArray::setValue() (rad 155 av /web/core/lib/Drupal/Component/Utility/NestedArray.php)... [rest of stack trace omitted]

Note that the patches offered below (with the exception of the debug patch) are essentially identical and differ only in the line number in core/lib/Drupal/Core/Form/FormBuilder.php where the change is applied.

The patch has worked for me (D9.5.9, PHP8.1) with custom views - again, with a different line number.

Proposed resolution

Modify core/lib/Drupal/Core/Form/FormBuilder.php:1242

Before:
NestedArray::setValue($form_state->getUserInput(), $element['#parents'], NULL);

After:
NestedArray::setValue($form_state->getUserInput(), $element['#parents'], NULL, TRUE);

Modify core/modules/views/src/Plugin/views/filter/NumericFilter.php:448
Before:

case 1:
    if ($value['value'] === '') {
              return FALSE;
            }

After:

case 1:
            if (isset($value['value']) && $value['value'] === '') {
              return FALSE;
            }
๐Ÿ› Bug report
Status

Needs work

Version

11.0 ๐Ÿ”ฅ

Component
Formย  โ†’

Last updated about 14 hours ago

Created by

๐Ÿ‡ซ๐Ÿ‡ทFrance hassebasse

Live updates comments and jobs are added and updated live.
  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

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