You are here

protected function FacetapiFacetProcessor::processHierarchy in Facet API 6.3

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

Processes hierarchical relationships between the facet items.

Parameters

array $build: The initialized render array.

Return value

array The initialized render array with processed hierarchical relationships.

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

File

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

Class

FacetapiFacetProcessor
Processes facets, initializes the build.

Code

protected function processHierarchy(array $build) {

  // Builds the hierarchy information if the hierarchy callback is defined.
  if ($this->facet['hierarchy callback']) {
    $parents = $this->facet['hierarchy callback'](array_keys($build));
    foreach ($parents as $value => $parents) {
      foreach ($parents as $parent) {
        if (isset($build[$parent]) && isset($build[$value])) {

          // Use a reference so we see the updated data.
          $build[$parent]['#item_children'][$value] =& $build[$value];
          $build[$value]['#item_parents'][$parent] = $parent;
        }
      }
    }
  }

  // Tests whether parents have an active child.
  // @todo: Can we make this more efficient?
  do {
    $active = 0;
    foreach ($build as $value => $item) {
      if ($item['#active'] && !empty($item['#item_parents'])) {

        // @todo Can we build facets with multiple parents? Core taxonomy
        // form cannot, so we will need a check here.
        foreach ($item['#item_parents'] as $parent) {
          if (!$build[$parent]['#active']) {
            $active = $build[$parent]['#active'] = 1;
          }
        }
      }
    }
  } while ($active);

  // Since the children are copied to their parent's "#item_parents" property
  // during processing, we have to filter the original child items from the
  // top level of the hierarchy.
  return array_filter($build, 'facetapi_filter_top_level_children');
}