In my contrib theme, I render the full main menu tree based on what changed with #2207893: Convert menu tree building to a service..


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');
  }
function gratis_menu_tree__primary(&$vars) {
  return '<ul class="toggle-menu">' . $vars['tree'] . '</ul>';
}

This new method above worked fine as of drupal 8-alpha11 but now with drupal 8.0.0-alpha14, I am getting this 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 part that says:

Did you mean this: "menu.link_tree"?

... is curious and at any rate, I tried that but it did not fix the issue either. My guess is that some other part of the menu system has changed between Alpha 11 and 14 but I just can't figure out what that is.

Comments

Danny Englander’s picture

Issue summary: View changes
larowlan’s picture

Hey Danny, yep there were major changes in the menu api. Don't have it in front of me but core.services.yml has all service names listed, you should be able to find new name in there. Also the issue that changed it was titled something like 'new plan menu links as plugins'

dawehner’s picture

Status: Active » Fixed

so this is fixed.

Danny Englander’s picture

Danny Englander’s picture

Also referencing the fix in case anyone else runs into this: #2322745: New method to render the full main menu tree now that menu links are plugins

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.