protected function MenuTreeStorage::treeDataRecursive in Colossal Menu 8
Same name and namespace in other branches
- 2.x src/Menu/MenuTreeStorage.php \Drupal\colossal_menu\Menu\MenuTreeStorage::treeDataRecursive()
Build the tree from the closure table.
Parameters
array $flat: A flat tree returned from the database.
array $links: An array of Link objects.
array $depth: An array of depth values.
array $routes: An array of route names.
Return value
array A fully-formed link tree.
1 call to MenuTreeStorage::treeDataRecursive()
- MenuTreeStorage::loadTreeData in src/
Menu/ MenuTreeStorage.php - Loads a menu link tree from the storage.
File
- src/
Menu/ MenuTreeStorage.php, line 218
Class
- MenuTreeStorage
- Provides a menu tree storage using the database.
Namespace
Drupal\colossal_menu\MenuCode
protected function treeDataRecursive(array $flat, array $links, array $depth, array $routes) {
uasort($flat, function ($a, $b) {
return count($a) - count($b);
});
$tree = [];
foreach ($flat as $id => $decendents) {
foreach ($decendents as $decendent) {
if ($id == $decendent) {
$active = FALSE;
if (isset($routes[$id]) && $this->currentRouteMatch
->getRouteName() == $routes[$id]) {
$active = TRUE;
}
$tree[$id] = [
'link' => $links[$id],
'has_children' => FALSE,
'subtree' => [],
'depth' => $depth[$id] + 1,
'in_active_trail' => $active,
];
}
else {
if (isset($tree[$decendent])) {
$tree[$id]['has_children'] = TRUE;
$tree[$id]['in_active_trail'] = $tree[$decendent]['in_active_trail'];
$tree[$id]['subtree'][$decendent] = $tree[$decendent];
unset($tree[$decendent]);
if (count($tree[$id]['subtree']) > 1) {
uasort($tree[$id]['subtree'], function ($a, $b) {
return $a['link']
->getWeight() < $b['link']
->getWeight() ? -1 : 1;
});
}
}
}
}
}
if (count($tree) > 1) {
uasort($tree, function ($a, $b) {
return $a['link']
->getWeight() < $b['link']
->getWeight() ? -1 : 1;
});
}
return $tree;
}