You are here

public function RangeSliderWidget::build in Facets 8

Builds the facet widget for rendering.

Parameters

\Drupal\facets\FacetInterface $facet: The facet we need to build.

Return value

array A renderable array.

Overrides SliderWidget::build

File

modules/facets_range_widget/src/Plugin/facets/widget/RangeSliderWidget.php, line 21

Class

RangeSliderWidget
The range slider widget.

Namespace

Drupal\facets_range_widget\Plugin\facets\widget

Code

public function build(FacetInterface $facet) {
  $build = parent::build($facet);
  if (empty($facet
    ->getResults())) {
    return $build;
  }
  $active = $facet
    ->getActiveItems();
  $facet_settings =& $build['#attached']['drupalSettings']['facets']['sliders'][$facet
    ->id()];
  $facet_settings['range'] = TRUE;
  $facet_settings['url'] = reset($facet_settings['urls']);
  unset($facet_settings['value']);
  unset($facet_settings['urls']);
  $min = $facet_settings['min'];
  $max = $facet_settings['max'];
  $facet_settings['values'] = [
    isset($active[0][0]) ? (double) $active[0][0] : $min,
    isset($active[0][1]) ? (double) $active[0][1] : $max,
  ];
  return $build;
}