public function TBMegaMenuBuilder::syncOrderMenus in The Better Mega Menu 2.x
Same name and namespace in other branches
- 8 src/TBMegaMenuBuilder.php \Drupal\tb_megamenu\TBMegaMenuBuilder::syncOrderMenus()
Sync order of menu items between menu and tb_megamenus.
Parameters
array $menu_config: The menu configuration.
Overrides TBMegaMenuBuilderInterface::syncOrderMenus
File
- src/
TBMegaMenuBuilder.php, line 459
Class
- TBMegaMenuBuilder
- Defines a TBMegaMenuBuilder.
Namespace
Drupal\tb_megamenuCode
public function syncOrderMenus(array &$menu_config) {
foreach ($menu_config as $mlid => $config) {
foreach ($config['rows_content'] as $rows_id => $row) {
$item_sorted = [];
// Get weight from items.
foreach ($row as $col) {
foreach ($col['col_content'] as $menu_item) {
if ($menu_item['type'] == 'menu_item') {
$item_sorted[$menu_item['weight']][] = $menu_item;
}
}
}
// Sort menu items by weight.
$item_sorted = self::sortByWeight($item_sorted);
// Update $menu_config to reflect new sort order.
foreach ($row as $rid => $col) {
foreach ($col['col_content'] as $menu_item_id => $menu_item) {
if ($menu_item['type'] == 'menu_item') {
$menu_config[$mlid]['rows_content'][$rows_id][$rid]['col_content'][$menu_item_id] = array_shift($item_sorted);
}
}
}
}
}
}