Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I am just trying to learn how the Drupal 8 menu system works.
The content_entity_example.links.menu.yml file contains:
content_entity_example.contact_list:
title: 'Content Entity Example: Contacts Listing'
route_name: content_entity_example.contact_list
description: 'List Contacts'
weight: 10
The menu entry ends up under the "Tools" menu. What I cannot figure out is how that happens. Is there a default location menus are put (.ie the Tools menu) if no parent is specified?
If I specify
parent: tools
it works the same way.
If I specify
parent: system.admin_structure
then the menu entry appears administration->structure menu as expected.
Was it just chance that the original coding works? Should the example have included " parent: tools" to be safe?
Comments
Comment #1
rpayanm@David4514 Please checkout again, because the code was changed.
Comment #2
Mile23It's a good strategy to look at the change notices: https://www.drupal.org/list-changes/
You can then search for the thing you're interested in, such as
links.menu.yml
: https://www.drupal.org/list-changes/published?keywords_description=links...Drilling down through the results there, we arrive at some documentation on how to do the thing you're talking about: https://www.drupal.org/node/2122241
That gives us some sample code:
So yup,
parent:
. :-)Eventually there will be a menu_example module as well, which should do a better job of explaining this.
Comment #3
David4514 CreditAttribution: David4514 commentedThanks @rpayanm, I've updated the examples module. I see that the content_entity_example.links.menu.yml have been updated, though I still would have questioned why the "List Contacts" showed up under the tools menu since neither parent nor menu_name are included.
@Mile23: I thought that I had read through the change record at https://www.drupal.org/node/2122241, but I could not say for sure. What I do see is that it now states that the tools menu will be the default if menu_name is not included. I'm not able to test at the moment, possibly this weekend, but I'm not sure that is correct. When I included the parent, but did not include the menu_name, it placed the menu link under the parent and no longer defaulted to the Tools menu.
Comment #4
Mile23We'll try to fold this info into menu_example: #1883724: Port menu_example to D8