protected function FacetapiFacetProcessor::processHierarchy in Facet API 7.2
Same name and namespace in other branches
- 6.3 plugins/facetapi/adapter.inc \FacetapiFacetProcessor::processHierarchy()
- 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. See the return of FacetapiFacetProcessor::initializeBuild() for the structure of the return array.
1 call to FacetapiFacetProcessor::processHierarchy()
- 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 1554 - Adapter plugin and adapter related classes.
Class
- FacetapiFacetProcessor
- Builds base render array used as a starting point for rendering.
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?
$settings = $this->facet
->getSettings();
if (!$settings->settings['individual_parent']) {
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');
}