You are here

public function FacetapiFacet::processActiveItems in Facet API 6

Finds and stores the facet's active items.

Return value

An instance of this class.

2 calls to FacetapiFacet::processActiveItems()
FacetapiFacet::getActiveItems in ./facetapi.adapter.inc
Returns the facet's active items.
FacetapiFacet::getActiveValues in ./facetapi.adapter.inc
Returns an array of the facet's active item values, most useful as a form element's default value.

File

./facetapi.adapter.inc, line 462
Defines classes used by the FacetAPI module.

Class

FacetapiFacet
Stores facet data, provides methods that build the facet's render array.

Code

public function processActiveItems() {
  $this->_active = array();

  // Bails if the facet isn't enabled in any realm.
  if (!facetapi_facet_enabled($this->_adapter
    ->getSearcher(), NULL, $this->_facet['name'])) {
    return $this;
  }

  // Gets active items from query string, normalizes to an array.
  $field_alias = $this->_facet['field alias'];
  if (isset($_GET[$field_alias])) {
    if (is_array($_GET[$field_alias])) {
      $data = $_GET[$field_alias];
    }
    else {
      $data = array(
        (string) $_GET[$field_alias],
      );
    }
  }
  else {
    $data = array();
  }

  // Allows hooks to add additional information to the active item. For
  // example, range queries extract the start and end values from the item.
  $hook = 'facetapi_value_' . $this->_facet['query type'];
  foreach ($data as $key => $value) {
    $this->_active[$value] = array(
      'pos' => $key,
      'value' => $value,
    );
    drupal_alter($hook, $this->_active[$value], $this->_adapter);
  }
  return $this;
}