public function AnonymousMenuLinkTreeManipulator::generateIndexAndSort in footermap: a footer site map 8
Generates a unique index and sorts by it.
Parameters
\Drupal\Core\Menu\MenuLinkTreeElement[] $tree: The menu link tree to manipulate.
Return value
\Drupal\Core\Menu\MenuLinkTreeElement[] The manipulated menu link tree.
File
- src/
Menu/ AnonymousMenuLinkTreeManipulator.php, line 234
Class
- AnonymousMenuLinkTreeManipulator
- Provides an anonymous-based menu link tree manipulator.
Namespace
Drupal\footermap\MenuCode
public function generateIndexAndSort(array $tree) {
$new_tree = [];
foreach ($tree as $key => $v) {
if ($tree[$key]->subtree) {
$tree[$key]->subtree = $this
->generateIndexAndSort($tree[$key]->subtree);
}
$instance = $tree[$key]->link;
// The weights are made a uniform 5 digits by adding 50000 as an offset.
// After $this->menuLinkCheckAccess(), $instance->getTitle() has the
// localized or translated title. Adding the plugin id to the end of the
// index insures that it is unique.
$new_tree[50000 + $instance
->getWeight() . ' ' . $instance
->getTitle() . ' ' . $instance
->getPluginId()] = $tree[$key];
}
ksort($new_tree);
return $new_tree;
}