Access menu links from a module I'm trying to display a menu in my module. I've used \Drupal::entityManager()-&gt;getStorage('menu')-&gt;load('oz-topbar-menu'); which allows me to get the title of the menu, the description, etc.

I obviously need the links of that menu, and I can't understand how to retrieve. From what I've read in the documentation I should probably use MenuLinkTreeInterface but I don't understand how to instantiate it.

I've tried \Drupal::menuTree()-&gt;load('oz-topbar-menu', $menu_parameters);. With basic menu parameters it returns a humongous amount of information; I'm guessing it must be the entire menu tree of Drupal.

I tried playing with the parameters of MenuTreeParameters (setTopLevelOnly, setRoot('oz-topbar-menu')) but it returns an empty array.

I've tried sending this as a MenuTreeParameters object with \Drupal::menuTree()-&gt;getCurrentRouteMenuTreeParameters('oz-topbar-menu'), but I still get a massive link tree.
You are probably just missing the build() call.

$menu_name = 'my-custom-menu';
$menu_parameters = \Drupal::menuTree()-&gt;getCurrentRouteMenuTreeParameters($menu_name);
$tree = \Drupal::menuTree()-&gt;load($menu_name, $menu_parameters);
$renderable = \Drupal::menuTree()-&gt;build($tree);
print \Drupal::service('renderer')-&gt;render($renderable);


Core is the best example for these kinds of things. I pulled the above from SystemMenuBlock::build().