Working with menu links
Now that we know how to load and manipulate trees of menu links, let's talk a bit more about the regular menu links. In this section, we will look at how our module can define menu links and how we can work with them programmatically once we get our hands on them from a tree or somewhere else.
Defining menu links
In our Hello World module, we defined a couple of routes, one of which maps to the /hello
path. Let's now create a link to that path that goes inside the main menu that is shipped with Drupal core.
As I mentioned, menu links are defined inside a *.links.menu.yml
file. So, let's create that file for our module and add our menu link definition in it:
hello_world.hello: title: 'Hello' description: 'Get your dynamic salutation.' route_name: hello_world.hello menu_name: main weight: 0
In a typical YAML notation, we have the machine name (in this...