TypeError: Cannot access offset of type string on string in Drupal\views\Plugin\views\filter\NumericFilter->valueForm()

Created on 29 December 2022, over 1 year ago
Updated 11 September 2023, 10 months ago

Problem/Motivation

TypeError: Cannot access offset of type string on string in Drupal\views\Plugin\views\filter\NumericFilter->valueForm() (line 239 of core/modules/views/src/Plugin/views/filter/NumericFilter.php).

Drupal\views\Plugin\views\filter\NumericFilter->valueForm(Array, Object) (Line: 40)
Drupal\views\Plugin\views\filter\Date->valueForm(Array, Object) (Line: 939)
Drupal\views\Plugin\views\filter\FilterPluginBase->buildExposedForm(Array, Object) (Line: 111)
Drupal\views\Form\ViewsExposedForm->buildForm(Array, Object)

Steps to reproduce

This error is triggered when passing an empty value to a query parameter for an exposed views filter, like this:
?date_ranges_start=&date_ranges_start_op=overlaps

Proposed resolution

Improve the isset() check.

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
ViewsΒ  β†’

Last updated about 3 hours ago

Created by

πŸ‡§πŸ‡ͺBelgium DieterHolvoet Brussels

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

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

  • πŸ‡ΊπŸ‡ΈUnited States bajah1701

    I'm experiencing this issue in Drupal 9.5.2 and the patch fails because there appears to be differences in the codebase at this line.
    What is the recommendation for raising this same issue but for a different version of Drupal?

  • πŸ‡ΊπŸ‡ΈUnited States bajah1701

    If this might help someone. I got this exact error message but this patch didn't work. I took @cilefen recommendation of the duplicate issue and decided to try its patch instead and voila, it works.

    So while the error message may be different, the solution is the same.

  • Status changed to Needs review 10 months ago
  • last update 10 months ago
    30,146 pass
  • πŸ‡ΊπŸ‡ΈUnited States jrb Raleigh-Durham Area, NC, USA

    @bajah1701

    I looked into the code a bit and noticed that line 238 & 255 is making use of the $identifier that isn't defined.

    $identifier is defined if $exposed is set, and it will be in lines 238 and 255 (it's checked).

    @DieterHolvoet

    I don't think these changes to $user_input are even really doing anything: $user_input = $form_state->getUserInput(); is not storing that array as reference and $form_state->setUserInput($user_input); is not called after doing those changes.

    This is definitely true, but was an issue in the code prior to this patch being added. Looking waaaaaay back, it actually appears to have been broken in this commit from 9 years ago that changed $form_state from an array to an object!

    https://git.drupalcode.org/issue/drupal-3330100/-/commit/de5fe262f2c2371...

    In it, they replaced all direct uses of $form_state['input'] with code like $user_input = $form_state->getUserInput() . They used $form_state->setUserInput($user_input) afterwards most everywhere, but not here. Maybe it's not all that important since no one has noticed in 9 years, but I'd say it should be added back.

    *****

    I don't have time right now to update the issue fork, but attached is a patch that adds $form_state->setUserInput($user_input) to the changes from the current MR. This fixes an issue for us where having "&price=" in an URL where price should be an array causes a the fatal error.

  • Status changed to Needs work 10 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Have not reviewed.

    But moving to NW for test cases

Production build 0.69.0 2024