0

Like it was said in subject, how would I do that?

I need to create menu items once after module install and have the ability to edit them if needed.

module.link.menu.yml won't give me that ability.

Anybody have suggestions?

1
  • I'm more of a Drupal 7 guy, but menu items and installation doesn't typically jibe ... usually menu paths are defined within the module. But I know D8 is totally different, so you might be able to ignore me. – joshmiller Feb 5 '16 at 16:25
1

You can use hook_menu_links_discovered_alter() to modify or add additional links to those provided in *.menu.links.yml files, but these types of links are not completely editable (e.g. you can not change their title in the UI).

If your links are content based, need to be completely editable later through the UI, or are being placed in a custom menu you can directly create the menu link entities:

MenuLinkContent::create([
  'title'      => 'My internal link from a route name',
  'link'       => ['uri' => 'route:myroute'],
  'menu_name'  => 'my-menu',
])->save();

Also check out the Entity API documentation, and Working with the Entity API for more information.

3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.