You are here

public function FacetapiFacet::buildItems in Facet API 6

Builds the render array for the facet's items.

Return value

A render array for the facet's items.

1 call to FacetapiFacet::buildItems()
FacetapiFacet::build in ./facetapi.adapter.inc
Returns the facet's render array.

File

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

Class

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

Code

public function buildItems() {
  $build = array();

  // Build array defaults.
  // @todo Use #markup in D7.
  $defaults = array(
    '#type' => 'markup',
    '#value' => '',
    '#indexed_value' => '',
    '#count' => 0,
    '#active' => 0,
    '#item_parents' => array(),
    '#item_children' => array(),
  );

  // Builds render arrays for each item.
  if (NULL !== $this->_facet['field']) {
    $hook = 'facetapi_facet_' . $this->_facet['query type'] . '_build';
    $items = (array) module_invoke($this->_adapter
      ->getModule(), $hook, $this->_adapter, $this->_facet);
  }
  else {
    $items = array();
  }
  foreach (element_children($items) as $value) {

    // @todo Use #markup in D7.
    $item_defaults = array(
      '#value' => $value,
      '#indexed_value' => $value,
      '#active' => $this
        ->itemActive($value),
    );

    // This seems silly, but it maintains the references to the child items
    // stored in the #item_children property.
    $items[$value] = array_merge($defaults, $item_defaults, $items[$value]);
    $build[$value] =& $items[$value];
  }

  // Maps the IDs to human readable values via the mapping callback.
  if (!empty($this->_facet['map callback']) && function_exists($this->_facet['map callback'])) {
    $map = call_user_func($this->_facet['map callback'], array_keys($build));
    array_walk($build, 'facetapi_ids_replace', $map);
  }
  return $build;
}