- πΊπΈ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
almost 2 years ago 12:49am 9 September 2023 - last update
almost 2 years 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
almost 2 years ago 5:20pm 11 September 2023 - πΊπΈUnited States smustgrave
Have not reviewed.
But moving to NW for test cases
- π³πΏNew Zealand jonathan_hunt
I encountered TypeError: Cannot access offset of type string on string in Drupal\views\Plugin\views\filter\NumericFilter->valueForm() (line 236 of /app/web/core/modules/views/src/Plugin/views/filter/NumericFilter.php) on Drupal 10.5.1 under different circumstances. I have a view showing a single field (identifier) and and aggregated count of identifier. I wanted to filter by identifier count > 1 (i.e. show only duplicated identifiers). When adding a filter for identifier, the views dialog would give an ajax error when changing the Aggregation type from default 'Group results together' to 'Count'. Debugging indicated
$this->value
unset inNumericFilter.php
. Watchdog shows the "Cannot access offset of type string on string" as the issue underlying the ajax error.
The following tests for a value before using allowed me to add an unexposed filter by count. However, perhaps a better solution would be to ensureNumericFilter.php $this->value
is set when switching to 'Count'.diff --git a/core/modules/views/src/Plugin/views/filter/GroupByNumeric.php b/core/modules/views/src/Plugin/views/filter/GroupByNumeric.php index d05c8f7d6b3..6b685c484ea 100644 --- a/core/modules/views/src/Plugin/views/filter/GroupByNumeric.php +++ b/core/modules/views/src/Plugin/views/filter/GroupByNumeric.php @@ -36,7 +36,7 @@ protected function opBetween($field) { protected function opSimple($field) { $placeholder = $this->placeholder(); - $this->query->addHavingExpression($this->options['group'], "$field $this->operator $placeholder", [$placeholder => $this->value['value']]); + $this->query->addHavingExpression($this->options['group'], "$field $this->operator $placeholder", [$placeholder => $this->value['value'] ?? '']); } protected function opEmpty($field) { diff --git a/core/modules/views/src/Plugin/views/filter/NumericFilter.php b/core/modules/views/src/Plugin/views/filter/NumericFilter.php index 1acda099041..7ded89a1a24 100644 --- a/core/modules/views/src/Plugin/views/filter/NumericFilter.php +++ b/core/modules/views/src/Plugin/views/filter/NumericFilter.php @@ -233,7 +233,7 @@ protected function valueForm(&$form, FormStateInterface $form_state) { '#type' => 'textfield', '#title' => !$exposed ? $this->t('Value') : '', '#size' => 30, - '#default_value' => $this->value['value'], + '#default_value' => $this->value['value'] ?? '', ]; if (!empty($this->options['expose']['placeholder'])) { $form['value']['value']['#attributes']['placeholder'] = $this->options['expose']['placeholder']; @@ -288,7 +288,7 @@ protected function valueForm(&$form, FormStateInterface $form_state) { '#type' => 'textfield', '#title' => $this->t('Min'), '#size' => 30, - '#default_value' => $this->value['min'], + '#default_value' => $this->value ?? $this->value['min'], ]; if (!empty($this->options['expose']['min_placeholder'])) { $form['value']['min']['#attributes']['placeholder'] = $this->options['expose']['min_placeholder']; @@ -297,7 +297,7 @@ protected function valueForm(&$form, FormStateInterface $form_state) { '#type' => 'textfield', '#title' => $this->t('Max'), '#size' => 30, - '#default_value' => $this->value['max'], + '#default_value' => $this->value ?? $this->value['max'], ]; if (!empty($this->options['expose']['max_placeholder'])) { $form['value']['max']['#attributes']['placeholder'] = $this->options['expose']['max_placeholder']; @@ -409,7 +409,7 @@ public function adminSummary() { if (in_array($this->operator, $this->operatorValues(2))) { $output .= ' ' . $this->t('@min and @max', ['@min' => $this->value['min'], '@max' => $this->value['max']]); } - elseif (in_array($this->operator, $this->operatorValues(1))) { + elseif (in_array($this->operator, $this->operatorValues(1)) && isset($this->value['value'])) { $output .= ' ' . $this->value['value']; } return $output;