showOperatorForm - Do not add empty prefix/suffix

Created on 7 December 2023, 7 months ago

Follow-up to 🐛 Claro - Views Filter Expose Option Form - Broken HTML Postponed: needs info

FilterPluginBase:showOperatorForm() unconditionally adds a prefix and a suffix div, even if the operator form is empty and therefor nothing will ever be rendered. In claro this leeds to unexpected behavior.

My suggestion therefor:

Alter

 public function showOperatorForm(&$form, FormStateInterface $form_state) {
    $this->operatorForm($form, $form_state);
    $form['operator']['#prefix'] = '<div class="views-group-box views-left-30">';
    $form['operator']['#suffix'] = '</div>';
  }

to

 public function showOperatorForm(&$form, FormStateInterface $form_state) {
    $this->operatorForm($form, $form_state);
    if (empty($form['operator'])) {
      return;
    }
    $form['operator']['#prefix'] = '<div class="views-group-box views-left-30">';
    $form['operator']['#suffix'] = '</div>';
  }
🐛 Bug report
Status

Active

Version

10.2

Component
Views 

Last updated about 1 hour ago

Created by

🇩🇪Germany ChristianAdamski Berlin, Germany

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

Comments & Activities

  • Issue created by @ChristianAdamski
  • 🇩🇪Germany ChristianAdamski Berlin, Germany
  • 🇮🇳India SandeepSingh199

    thanks @ChristianAdamski, In this issue summary you also provided solution. This bug need to fixed in Drupal 10.1, 10.2 & Drupal 11.

  • 🇳🇱Netherlands Lendude Amsterdam

    The same happens in Gin. Not 100% sure if this is a core issue or if this should be fixed in the themes or in the filter plugin without the operators, but probably cleanest to do it in core.
    Should we consider BC? We are assuming themes don't account for this (Claro and Gin don't) but what will happen to themes that do account for this? Do we want/need to take that into consideration?

Production build 0.69.0 2024