diff --git a/modules/facets_exposed_filters/src/Plugin/views/filter/FacetsFilter.php b/modules/facets_exposed_filters/src/Plugin/views/filter/FacetsFilter.php index 93ff150443068f88f1d0744aa3b54d0aaeb771f3..872d5ffb5e233d21cdf9dc88291e12af622b9ce3 100644 --- a/modules/facets_exposed_filters/src/Plugin/views/filter/FacetsFilter.php +++ b/modules/facets_exposed_filters/src/Plugin/views/filter/FacetsFilter.php @@ -84,7 +84,22 @@ class FacetsFilter extends FilterPluginBase { * {@inheritdoc} */ public function valueForm(&$form, FormStateInterface $form_state) { - $form['value'] = []; + // Build a version of the element without options, they'll be added later. + $form['value'] = [ + '#type' => 'select', + '#options' => [], + '#multiple' => $this->options["expose"]["multiple"], + ]; + + $exposed_form_type = $this->displayHandler->getPlugin('exposed_form')->getPluginId(); + if ($exposed_form_type == 'bef') { + $form['value']['#process'] = ['facets_exposed_filters_remove_validation']; + } + else { + // We need to merge the existing #process callbacks with our own. + $select_element = \Drupal::service('element_info')->getInfo('select'); + $form['value']['#process'] = array_merge($select_element["#process"], ['facets_exposed_filters_remove_validation']); + } // Extra checks when in views UI. if (isset($_POST["form_id"]) && $_POST["form_id"] === 'view_preview_form') { @@ -165,23 +180,12 @@ class FacetsFilter extends FilterPluginBase { facets_exposed_filters_get_processed_facet($this->view->id(), $this->view->current_display, $this->options["id"], $facet); } - // We need to merge the existing #process callbacks with our own. - $select_element = \Drupal::service('element_info')->getInfo('select'); - $this->value = $facet->getActiveItems(); // Store processed results so other modules can use these. $this->facet_results = $facet->getResults(); - $form['value'] = [ - '#type' => 'select', - '#options' => $this->buildOptions($facet->getResults(), $facet), - '#multiple' => $this->options["expose"]["multiple"], - '#process' => array_merge($select_element["#process"], ['facets_exposed_filters_remove_validation']), - ]; - $exposed_form_type = $this->displayHandler->getPlugin('exposed_form')->getPluginId(); - if ($exposed_form_type == 'bef') { - $form['value']['#process'] = ['facets_exposed_filters_remove_validation']; - } + // Populate the element with facet's options. + $form['value']['#options'] = $this->buildOptions($facet->getResults(), $facet); } /**