Warning: Undefined array key "value" in Drupal\views\Plugin\views\filter\NumericFilter->acceptExposedInput()

Created on 31 January 2024, 5 months ago
Updated 14 June 2024, 14 days ago

Problem/Motivation

Views exposed filter on an entity reference field generates a php warning with grouped filter type set to "Allow multiple selections." In my case, the warning happened after adding more than one distinct entity reference field filter.

Warning: Undefined array key "value" in Drupal\views\Plugin\views\filter\NumericFilter->acceptExposedInput() (line 442 of core/modules/views/src/Plugin/views/filter/NumericFilter.php).

I think this is happening because the code is trying to access the 'values' key in array $info[$this->operator] but really should be checking whether the 'values' key exists before attempting to access it.

Steps to reproduce

  1. Create entity type and entities within that type with two or more entity reference fields.
  2. Create a view filtering on that content type
  3. Add filters for the entity reference fields. For each of those filters:
    1. Select "Expose this filter to visitors..."
    2. Select "Grouped filters"
    3. Select "Allow multiple selections"
    4. (In my case, the operator is "Is not empty (NOT NULL)" and I have one grouping per filter – to get the checkbox)
  4. Visit the display of the view. The error appears on page load before you select anything.

The filters work, but the warning is persistent.

Proposed resolution

In web/core/modules/views/src/Plugin/views/filter/NumericFilter.php replace this:

$info = $this->operators();
if (!empty($info[$this->operator]['values'])) {
  switch ($info[$this->operator]['values']) {
    case 1:
      if ($value['value'] === '') {
        return FALSE;
      }
      break;

    case 2:
      if ($value['min'] === '' && $value['max'] === '') {
        return FALSE;
      }
      break;
  }
}

with:

$info = $this->operators();
if (isset($info[$this->operator]['values'])) {
  switch ($info[$this->operator]['values']) {
    case 1:
      if (isset($value['value']) && $value['value'] === '') {
        return FALSE;
      }
      break;

    case 2:
      if (isset($value['min'], $value['max']) && $value['min'] === '' && $value['max'] === '') {
        return FALSE;
      }
      break;
  }
}
🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Views 

Last updated less than a minute ago

Created by

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.

Production build 0.69.0 2024