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
Comment #1
Danny EnglanderComment #2
larowlanHey 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'
Comment #3
larowlan#2256521: [META] New plan, Phase 2: Implement menu links as plugins, including static admin links and views, and custom links with menu_link_content entity, all managed via menu_ui module is the issue you want
https://www.drupal.org/node/2226481 is the change notice
Comment #4
dawehnerso this is fixed.
Comment #5
Danny EnglanderCross referencing: http://drupal.stackexchange.com/questions/126477/drupal-8-implement-menu...
Comment #6
Danny EnglanderAlso 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