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
- Install BEF module.
- Create or edit any view.
- Set Exposed form style to use Better Exposed Filters in Exposed form settings.
- Add any date exposed filter with Is between operator. For example, node's created date filter.
- Go to Exposed form style settings and open it in new tab.
- 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.
}
Issue fork better_exposed_filters-3506688
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:
- 3506688-date-exposed-filter
changes, plain diff MR !151
Comments
Comment #3
deimos commentedI added some workaround to solve issue. You're welcome to provide any better fix for this issue :)
Comment #4
smustgrave commentedWith 6.0.x support low is this a problem in 7.0.x?
Comment #5
vanessa.fayard commentedHi!
I didn't reproduce the error in 7.0.x
Comment #7
smustgrave commentedSince not reproducible in 7.0.x going to close out, if experiencing that there please please reopen.