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

rpayanm’s picture

@David4514 Please checkout again, because the code was changed.

Mile23’s picture

It'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:

example.admin:
  title: 'Example settings'
  description: 'Manage example settings for your site'
  parent: system.admin_config_development

So yup, parent:. :-)

Eventually there will be a menu_example module as well, which should do a better job of explaining this.

David4514’s picture

Thanks @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.

Mile23’s picture

Status: Active » Closed (duplicate)

We'll try to fold this info into menu_example: #1883724: Port menu_example to D8