link; // Get the menu name of the first link. $menu_name = $first_link->getMenuName(); // Add a more specific theme suggestion to differentiate this rendered // menu from others. $build['#menu_name'] = $menu_name; $build['#theme'] = 'navigation_menu__' . strtr($menu_name, '-', '_'); // Loop through menu items and add the plugin id as a class. foreach ($tree as $item) { if ($item->access->isAllowed()) { $plugin_id = $item->link->getPluginId(); $plugin_class = Html::getClass(str_replace('.', '_', $plugin_id)); $build['#items'][$plugin_id]['class'] = $plugin_class; $url = $build['#items'][$plugin_id]['url']; $icon_defaults = [ 'pack_id' => 'navigation', 'icon_id' => $plugin_class, 'settings' => [ 'class' => 'toolbar-button__icon', 'size' => 20, ], ]; $build['#items'][$plugin_id]['icon'] = NestedArray::mergeDeep($icon_defaults, $url->getOption('icon') ?? []); } } return $build; } /** * {@inheritdoc} */ public function transform(array $tree, array $manipulators) { $tree = parent::transform($tree, $manipulators); $this->moduleHandler->alter('navigation_menu_link_tree', $tree); return $tree; } }