public function RangeSliderProcessor::build in Facets 8
Runs before the renderable array is created.
Parameters
\Drupal\facets\FacetInterface $facet: The facet being changed.
\Drupal\facets\Result\ResultInterface[] $results: The results being changed.
Return value
\Drupal\facets\Result\ResultInterface[] The changed results.
Overrides BuildProcessorInterface::build
File
- modules/
facets_range_widget/ src/ Plugin/ facets/ processor/ RangeSliderProcessor.php, line 45
Class
- RangeSliderProcessor
- Provides a processor that adds all range values between an min and max range.
Namespace
Drupal\facets_range_widget\Plugin\facets\processorCode
public function build(FacetInterface $facet, array $results) {
/** @var \Drupal\facets\Plugin\facets\processor\UrlProcessorHandler $url_processor_handler */
$url_processor_handler = $facet
->getProcessors()['url_processor_handler'];
$url_processor = $url_processor_handler
->getProcessor();
$active_filters = $url_processor
->getActiveFilters();
if (isset($active_filters[''])) {
unset($active_filters['']);
}
/** @var \Drupal\facets\Result\ResultInterface[] $results */
foreach ($results as &$result) {
$new_active_filters = $active_filters;
unset($new_active_filters[$facet
->id()]);
// Add one generic query filter with the min and max placeholder.
$new_active_filters[$facet
->id()][] = '(min:__range_slider_min__,max:__range_slider_max__)';
$url = \Drupal::service('facets.utility.url_generator')
->getUrl($new_active_filters, FALSE);
$result
->setUrl($url);
}
return $results;
}