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 Exposed form style to use Better Exposed Filters in Exposed form settings.
  4. Add any date exposed filter with Is between operator. For example, node's created date filter.
  5. Go to Exposed form style 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 user input is NULL. 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.
      }
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

deimos created an issue. See original summary.

deimos’s picture

Status: Active » Needs work

I added some workaround to solve issue. You're welcome to provide any better fix for this issue :)

smustgrave’s picture

Status: Needs work » Postponed (maintainer needs more info)

With 6.0.x support low is this a problem in 7.0.x?

vanessa.fayard’s picture

Hi!

I didn't reproduce the error in 7.0.x

smustgrave’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)

Since not reproducible in 7.0.x going to close out, if experiencing that there please please reopen.