- πΊπΈUnited States mrweiner
In case anybody else stumbles upon this, I implemented the following to use a specific menu to populate the links in the toolbar.
function module_preprocess_links__toolbar_user(&$variables) { $menu_tree_service = \Drupal::service('menu.link_tree'); $menu_name = 'user-toolbar'; $parameters = new MenuTreeParameters(); $parameters->setActiveTrail([$menu_name]); $main_tree_loaded = $menu_tree_service->load($menu_name, $parameters); $main_tree_built = $menu_tree_service->build($main_tree_loaded); // Note that this uses laravel collections, but you could do the same with a standard array_map $links = collect($main_tree_built['#items']) ->map(function (array $item) use ($variables) { return [ 'link' => [ '#type' => 'link', '#title' => t($item['title']), '#url' => $item['url'], ], 'text' => t($item['title']), 'attributes' => $item['attributes'], ]; }); $variables['links'] = $links->toArray(); }