You are here

public function FacetapiAdapter::processActiveItems in Facet API 7

Same name and namespace in other branches
  1. 6.3 plugins/facetapi/adapter.inc \FacetapiAdapter::processActiveItems()
  2. 7.2 plugins/facetapi/adapter.inc \FacetapiAdapter::processActiveItems()

Processes active facet items.

Instantiates the query type plugins for all enabled facets. Extracts active items from the source, usually the query string, and uses the query type plugins to extract any additional information such as the start and end values for ranges.

See also

FacetapiAdapter::setParams()

1 call to FacetapiAdapter::processActiveItems()
FacetapiAdapter::setParams in plugins/facetapi/adapter.inc
Processes and stores the extracted facet data.

File

plugins/facetapi/adapter.inc, line 286
Adapter plugin and adapter related classes.

Class

FacetapiAdapter
Abstract class extended by Facet API adapters.

Code

public function processActiveItems() {
  $this->activeItems = array(
    'facet' => array(),
    'filter' => array(),
  );

  // Refresh the query type plugins for all enabled facets.
  $this->queryTypes = $this
    ->loadQueryTypePlugins();

  // Group enabled facets by facet alias. It is possible for aliases to be
  // common across different facets, although they are usually unique.
  $enabled_aliases = array();
  foreach ($this
    ->getEnabledFacets() as $facet) {
    $enabled_aliases[$facet['field alias']][] = $facet['name'];
    $this->activeItems['facet'][$facet['name']] = array();
  }

  // Get the stored facet data and iterate over the passed values.
  $filter_key = $this->urlProcessor
    ->getFilterKey();
  $params = $this->urlProcessor
    ->getParams();
  foreach ($params[$filter_key] as $pos => $filter) {

    // Bail if the value is not a scalar, for example an object or array.
    if (!is_scalar($filter)) {
      continue;
    }

    // Perform basic parsing of the filter.
    $parts = explode(':', $filter, 2);

    // We need to filter out possible XSS attack function calls.
    foreach ($parts as $id => $part) {
      $parts[$id] = filter_xss($part);
    }
    $field_alias = rawurldecode($parts[0]);
    if (isset($parts[1]) && isset($enabled_aliases[$field_alias])) {
      $filter = $field_alias . ':' . $parts[1];

      // @see https://www.drupal.org/node/1884152
      // Store basic information about the active item. For details on how
      // this array is structured, refer to the FacetapiAdapter::activeItems
      // docblock.
      $item = array(
        'field alias' => $field_alias,
        'value' => $parts[1],
        'pos' => $pos,
      );

      // Initialize and populate the active items. For details on how this
      // array is structured, refer to the FacetapiAdapter::activeItems
      // docblock.
      $this->activeItems['filter'][$filter] = $item;
      $this->activeItems['filter'][$filter]['facets'] = array();
      foreach ($enabled_aliases[$field_alias] as $facet_name) {
        $item += $this->queryTypes[$facet_name]
          ->extract($item);
        $this->activeItems['filter'][$filter]['facets'][] = $facet_name;
        $this->activeItems['facet'][$facet_name][$parts[1]] = $item;
      }
    }
  }
}