2 of 2
deleted 18 characters in body
4uk4
  • 99.7k
  • 7
  • 169
  • 216

While D8 uses the symfony routing system and configures this with yml files and dynamic route callbacks as described by @MrD, menus are now a separate system.

The menu system offers two ways to define menu links. Static in mymodule.links.menu.yml and dynamic as content.

To do the latter add an item to a menu by creating a MenuLinkContent entity:

$item = \Drupal\menu_link_content\Entity\MenuLinkContent::create([
  'link' => ['uri' => 'internal:/<front>'],
  'title' => 'Front Page',
  'menu_name' => 'admin',
]);
$item->save();

A more complex example would be how drupal generates the menu link when it saves a node:

https://api.drupal.org/api/drupal/core!modules!menu_ui!menu_ui.module/function/_menu_ui_node_save/8.2.x

4uk4
  • 99.7k
  • 7
  • 169
  • 216