Skip to content
Snippets Groups Projects

3446040: Always build the facet element without options rather than returning a completely empty element in some cases

1 file
+ 18
14
Compare changes
  • Side-by-side
  • Inline
@@ -84,7 +84,22 @@ class FacetsFilter extends FilterPluginBase {
@@ -84,7 +84,22 @@ class FacetsFilter extends FilterPluginBase {
* {@inheritdoc}
* {@inheritdoc}
*/
*/
public function valueForm(&$form, FormStateInterface $form_state) {
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.
// Extra checks when in views UI.
if (isset($_POST["form_id"]) && $_POST["form_id"] === 'view_preview_form') {
if (isset($_POST["form_id"]) && $_POST["form_id"] === 'view_preview_form') {
@@ -165,23 +180,12 @@ class FacetsFilter extends FilterPluginBase {
@@ -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);
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();
$this->value = $facet->getActiveItems();
// Store processed results so other modules can use these.
// Store processed results so other modules can use these.
$this->facet_results = $facet->getResults();
$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();
// Populate the element with facet's options.
if ($exposed_form_type == 'bef') {
$form['value']['#options'] = $this->buildOptions($facet->getResults(), $facet);
$form['value']['#process'] = ['facets_exposed_filters_remove_validation'];
}
}
}
/**
/**
Loading