You are here

protected function FacetapiFacetProcessor::initializeBuild in Facet API 6.3

Same name and namespace in other branches
  1. 7.2 plugins/facetapi/adapter.inc \FacetapiFacetProcessor::initializeBuild()
  2. 7 plugins/facetapi/adapter.inc \FacetapiFacetProcessor::initializeBuild()

Initializes the facet's render array.

Return value

array The initialized render array.

1 call to FacetapiFacetProcessor::initializeBuild()
FacetapiFacetProcessor::process in plugins/facetapi/adapter.inc
Processes the facet items.

File

plugins/facetapi/adapter.inc, line 1200
Adapter plugin and adapter related calsses.

Class

FacetapiFacetProcessor
Processes facets, initializes the build.

Code

protected function initializeBuild() {
  $build = array();

  // Build array defaults.
  $defaults = array(
    '#value' => '',
    '#path' => $this->facet
      ->getAdapter()
      ->getSearchPath(),
    '#html' => FALSE,
    '#indexed_value' => '',
    '#count' => 0,
    '#active' => 0,
    '#item_parents' => array(),
    '#item_children' => array(),
  );

  // Builds render arrays for each item.
  $adapter = $this->facet
    ->getAdapter();
  $build = $adapter
    ->getFacetQuery($this->facet
    ->getFacet())
    ->build();

  // Invoke the alter callbacks for the facet.
  foreach ($this->facet['alter callbacks'] as $callback) {
    $callback($build, $adapter, $this->facet
      ->getFacet());
  }

  // Iterates over the render array and merges in defaults.
  foreach (element_children($build) as $value) {
    $item_defaults = array(
      '#value' => $value,
      '#indexed_value' => $value,
      '#active' => $adapter
        ->itemActive($this->facet['name'], $value),
    );
    $build[$value] = array_merge($defaults, $item_defaults, $build[$value]);
  }
  return $build;
}