public static function WeMegaMenuBuilder::getMenuItems in Drupal Mega Menu 8
Same name and namespace in other branches
- 8.x src/WeMegaMenuBuilder.php \Drupal\we_megamenu\WeMegaMenuBuilder::getMenuItems()
Get menu items list.
Return value
array Public static function getMenuItems array.
2 calls to WeMegaMenuBuilder::getMenuItems()
- WeMegaMenuBuilder::dragDropMenuItems in src/
WeMegaMenuBuilder.php - Drag-Drop menu item insert.
- WeMegaMenuBuilder::repositionMenuItems in src/
WeMegaMenuBuilder.php - Reposition menu items based on what changed
File
- src/
WeMegaMenuBuilder.php, line 151
Class
Namespace
Drupal\we_megamenuCode
public static function getMenuItems($menu_name, $items = [], $level = 0, &$result = []) {
if ($level == 0) {
$menu_active_trail = Drupal::service('menu.active_trail')
->getActiveTrailIds($menu_name);
$menu_tree_parameters = (new MenuTreeParameters())
->setActiveTrail($menu_active_trail)
->onlyEnabledLinks();
$tree = Drupal::menuTree()
->load($menu_name, $menu_tree_parameters);
foreach ($tree as $item) {
$route_name = $item->link
->getPluginDefinition()['id'];
$uuid = $route_name == 'standard.front_page' ? $item->link
->getPluginDefinition()['id'] : $item->link
->getDerivativeId();
$result[$uuid] = [];
if ($item->hasChildren) {
foreach ($item->subtree as $key_menu => $menu) {
$result[$uuid][] = $menu->link
->getDerivativeId();
}
}
self::getMenuItems($menu_name, $item, $level + 1, $result);
}
}
else {
if ($items->hasChildren) {
foreach ($items->subtree as $key_item => $item) {
$route_name = $item->link
->getPluginDefinition()['id'];
$uuid = $route_name == 'standard.front_page' ? $item->link
->getPluginDefinition()['id'] : $item->link
->getDerivativeId();
$result[$uuid] = [];
if ($item->hasChildren) {
foreach ($item->subtree as $key_menu => $menu) {
$result[$uuid][] = $menu->link
->getDerivativeId();
}
}
self::getMenuItems($menu_name, $item, $level + 1, $result);
}
}
}
return $result;
}