You are here

protected function FacetapiFacetProcessor::initializeBuild in Facet API 7.2

Same name and namespace in other branches
  1. 6.3 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 containing:

  • #markup: The value displayed to the user.
  • #path: The href of the facet link.
  • #html: Whether #markup is HTML. If TRUE, it is assumed that the data has already been properly been sanitized for display.
  • #indexed_value: The raw value stored in the index.
  • #count: The number of items in the result set.
  • #active: An integer flagging whether the facet is active or not.
  • #item_parents: An array of the parent index values.
  • #item_children: References to the child render arrays.
1 call to FacetapiFacetProcessor::initializeBuild()
FacetapiFacetProcessor::process in plugins/facetapi/adapter.inc
Builds the base render array used as a starting point for rendering.

File

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

Class

FacetapiFacetProcessor
Builds base render array used as a starting point for rendering.

Code

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

  // Build array defaults.
  $defaults = array(
    '#markup' => '',
    '#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.
  // @see https://www.drupal.org/node/1398036 for why array_keys() is used
  // instead of element_children().
  foreach (array_keys($build) as $value) {
    $item_defaults = array(
      '#markup' => $value,
      '#indexed_value' => $value,
      '#active' => $adapter
        ->itemActive($this->facet['name'], $value),
    );
    $build[$value] = array_merge($defaults, $item_defaults, $build[$value]);
  }
  return $build;
}