In a previous Drupal 8 menu question here, we determined that menu tree building was now a service. In my D8 contrib theme, I was then able to render the main menu tree as:
function gratis_preprocess_page(&$vars, $hook) {
// Build the main menu links tree.
if (!empty($vars['main_menu'])) {
// Build links.
$config = Drupal::config('menu.settings');
$menu_enabled = Drupal::moduleHandler()->moduleExists('menu');
// When menu module is not enabled, we need hardcoded default values.
$main_links_source = $menu_enabled ? $config->get('main_links') : 'main';
$vars['main_menu'] = \Drupal::service('menu_link.tree')->renderMenu($main_links_source);
$vars['main_menu']['#attributes']['id'] = 'main-menu-links';
$vars['main_menu']['#attributes']['class'] = array('links', 'clearfix');
$vars['main_menu']['#theme_wrappers'] = array('menu_tree__primary');
}
}
The key to this is the use of:
$vars['main_menu'] = \Drupal::service('menu_link.tree')->renderMenu($main_links_source);
This worked great to fix my main menu tree in Drupal 8 Alpha 11. However, there have been more sweeping changes to the menu system since then and now in Drupal 8.0.x Alpha14, this breaks again with the error:
Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service "menu_link.tree". Did you mean this: "menu.link_tree"? in Symfony\Component\DependencyInjection\Container->get() (line 303 of /Users/danny/Sites/Drupal/d8/drupal8/core/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/Container.php).
The thing that stands out from the above seems to be:
Did you mean this: "menu.link_tree"?
I tried
$vars['main_menu'] = \Drupal::service('menu.link_tree')->renderMenu($main_links_source);
... but that does not work either.
I filed a core issue here and that lead me to "[META] New plan, Phase 2: Implement menu links as plugins" and the very same change notice which I used to upgrade this code originally. Admittedly, I am pretty lost here.