Date exposed filter with "between" operator errors in BEF settings

Created on 14 February 2025, about 2 months ago

Problem/Motivation

TypeError: Drupal\Core\Form\FormState::setUserInput(): Argument #1 ($user_input) must be of type array, null given, called in /var/www/web/core/modules/views/src/Plugin/views/filter/Date.php on line 261 in Drupal\Core\Form\FormState->setUserInput() (line 1018 of core/lib/Drupal/Core/Form/FormState.php).

Drupal\views\Plugin\views\filter\Date->buildExposedForm(Array, Object) (Line: 399)
Drupal\better_exposed_filters\Plugin\better_exposed_filters\filter\FilterWidgetBase->getExposedFilterWidgetType() (Line: 96)
Drupal\better_exposed_filters\Plugin\better_exposed_filters\filter\FilterWidgetBase->buildConfigurationForm(Array, Object) (Line: 586)
Drupal\better_exposed_filters\Plugin\views\exposed_form\BetterExposedFilters->buildOptionsForm(Array, Object) (Line: 1833)
Drupal\views\Plugin\views\display\DisplayPluginBase->buildOptionsForm(Array, Object) (Line: 438)
Drupal\views\Plugin\views\display\PathPluginBase->buildOptionsForm(Array, Object) (Line: 279)
Drupal\views\Plugin\views\display\Page->buildOptionsForm(Array, Object) (Line: 74)
Drupal\views_ui\Form\Ajax\Display->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 536)
Drupal\Core\Form\FormBuilder->retrieveForm('views_ui_edit_display_form', Object) (Line: 284)
Drupal\Core\Form\FormBuilder->buildForm('Drupal\views_ui\Form\Ajax\Display', Object) (Line: 97)

Steps to reproduce

Issue discovered with better_exposed_filters: 6.0.6

  1. Install BEF module.
  2. Create or edit any view.
  3. Set to use in settings.
  4. Add any date exposed filter with operator. For example, node's created date filter.
  5. Go to settings and open it in new tab.
  6. Observe error.

Proposed resolution

I don't know exact cause of the issue but for Date plugin' exposed form when it is built from BEF . And farther set of user input causes error.
At the same time user input isn't NULL when Date exposed filter form is built as usual when you view page/block.

core/modules/views/src/Plugin/views/filter/Date.php

/**
 * Filter to handle dates stored as a timestamp.
 *
 * @ingroup views_filter_handlers
 */
#[ViewsFilter("date")]
class Date extends NumericFilter {

...

  /**
   * Override parent method to change input type.
   */
  public function buildExposedForm(&$form, FormStateInterface $form_state) {
    parent::buildExposedForm($form, $form_state);

...

      if (in_array($this->operator, ['between', 'not between'], TRUE)) {
        // Check the element input matches the form structure.
        $input = $form_state->getUserInput(); // $input === NULL;
        if (isset($input[$field_identifier], $input[$field_identifier]['min']) && !is_array($input[$field_identifier]['min']) && $value = $input[$field_identifier]['min']) {
          $date = new DrupalDateTime($value);
          $input[$field_identifier]['min'] = [
            'date' => $date->format('Y-m-d'),
            'time' => $date->format('H:i:s'),
          ];
        }
        if (isset($input[$field_identifier], $input[$field_identifier]['max']) && !is_array($input[$field_identifier]['max']) && $value = $input[$field_identifier]['max']) {
          $date = new DrupalDateTime($value);
          $input[$field_identifier]['max'] = [
            'date' => $date->format('Y-m-d'),
            'time' => $date->format('H:i:s'),
          ];
        }
        $form_state->setUserInput($input); // Error here.
      }
πŸ› Bug report
Status

Active

Version

6.0

Component

Code

Created by

πŸ‡ΊπŸ‡¦Ukraine deimos

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024