2 deleted 18 characters in body
source | link

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 this,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 for the task you have 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

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 this, 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 for the task you have 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

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

1
source | link

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 this, 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 for the task you have 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