You are here

protected function QueryString::initializeActiveFilters in Facets 8

Initializes the active filters from the request query.

Get all the filters that are active by checking the request query and store them in activeFilters which is an array where key is the facet id and value is an array of raw values.

1 call to QueryString::initializeActiveFilters()
QueryString::__construct in src/Plugin/facets/url_processor/QueryString.php
Constructs a new instance of the class.

File

src/Plugin/facets/url_processor/QueryString.php, line 321

Class

QueryString
Query string URL processor.

Namespace

Drupal\facets\Plugin\facets\url_processor

Code

protected function initializeActiveFilters() {
  $url_parameters = $this->request->query;

  // Get the active facet parameters.
  $active_params = $url_parameters
    ->get($this->filterKey, [], TRUE);
  $facet_source_id = $this->configuration['facet']
    ->getFacetSourceId();

  // When an invalid parameter is passed in the url, we can't do anything.
  if (!is_array($active_params)) {
    return;
  }

  // Explode the active params on the separator.
  foreach ($active_params as $param) {
    $explosion = explode($this
      ->getSeparator(), $param);
    $url_alias = array_shift($explosion);
    $facet_id = $this
      ->getFacetIdByUrlAlias($url_alias, $facet_source_id);
    $value = '';
    while (count($explosion) > 0) {
      $value .= array_shift($explosion);
      if (count($explosion) > 0) {
        $value .= $this
          ->getSeparator();
      }
    }
    if (!isset($this->activeFilters[$facet_id])) {
      $this->activeFilters[$facet_id] = [
        $value,
      ];
    }
    else {
      $this->activeFilters[$facet_id][] = $value;
    }
  }
}