Problem/Motivation

On a display using the Better Exposed Filters (with layout) exposed form style, clicking Change under Layout settings in the exposed form settings dialog fails with an AJAX HTTP 500:

TypeError: Drupal\Core\Form\SubformState::createForSubform(): Argument #1 ($subform) must be of type array, null given, called in better_exposed_filters/src/Plugin/views/exposed_form/BetterExposedFilters.php on line 773
...
Drupal\better_exposed_filters\Plugin\views\exposed_form\BetterExposedFilters->submitOptionsForm()
Drupal\views\Plugin\views\display\DisplayPluginBase->submitOptionsForm()
Drupal\views\Plugin\views\display\PathPluginBase->submitOptionsForm()
Drupal\views\Plugin\views\display\Page->submitOptionsForm()
Drupal\vefl_bef\Plugin\views\exposed_form\VeflBef->updateRegions()

VeflTrait::updateRegions() is the button's #submit handler, so it receives the complete form, and it hands that straight to the display:
$display->submitOptionsForm($form, $form_state);

The display expects only the options subform. This is what Views UI's own Apply button passes, in \Drupal\views_ui\Form\Ajax\Display::submitForm():
->submitOptionsForm($form['options'], $form_state);

DisplayPluginBase::submitOptionsForm() then passes $form['exposed_form_options'] to the exposed form plugin. Given the complete form, that key does not exist, so the plugin receives NULL. The core
Basic plugin reads only $form_state values, so Basic (with layout) does not notice. Better Exposed Filters builds a SubformState for each widget from $form['bef'][...]['configuration'],
and fails on the first one.

Found with Drupal 11.4, Better Exposed Filters 8.0.0-alpha1 and vefl 8.x-3.2, with the BEF 7 compatibility MR from #3161777 applied. It is not specific to BEF 8: BetterExposedFilters::submitOptionsForm() builds the widget subforms from $form['bef'][...]['configuration'] on the 6.0.x, 7.0.x, 7.1.x and 8.0.x branches alike.

Steps to reproduce

  1. Install vefl, vefl_bef and Better Exposed Filters.
  2. Edit a view with exposed filters and set the exposed form style to Better Exposed Filters (with layout).
  3. Open the exposed form settings, expand Layout settings, pick a layout and click Change.
  4. The dialog fails with the AJAX error above.

Proposed resolution

Pass the options subform, as Views UI does:

-    $display->submitOptionsForm($form, $form_state);
+    $display->submitOptionsForm($form['options'], $form_state);

With this change, the button submits and the chosen layout and its widget_region list are saved to the view.

The optionsOverride() call before it is a no-op for this section. exposed_form_options is not in DisplayPluginBase::defaultableSections(), so setOverride() returns early. It is left
alone here.

Remaining tasks

  • Review.
  • Follow-up, not addressed here: the button's own value is saved into the plugin options as layout.change: Change, and ends up in exported view config.

User interface changes

None. The Change button works.

API changes

None.

Data model changes

None.

Issue fork vefl-3632085

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

mortona2k created an issue. See original summary.

mortona2k’s picture

Status: Active » Needs review