2

I have a module with a menu link which I want to appear as a child of another link in the admin menu. The would-be-parent link is to a Views page if that matters.

This is the contents of mymodule.links.menu.yml:

mymodule.add_location:
  route_name: mymodule.add_form
  parent: views.branch_locations.page
  description: 'Add a foo.'
  title: Add new
  menu_name: admin

I got the views.branch_locations.page machine name for the desired parent link from ViewsMenuLink::getDerivativeDefinitions(), the class responsible for dynamically providing menu links for the Views module.

With the current setup the "Add new" item doesn't appear under "Branch Locations" in the admin menu. The route_name definitely exists, and no error is thrown when clearing cache or rebuilding menus, which suggests Drupal is accepting views.branch_locations.page as a valid parent link somewhere along the line.

But how do I get this item to show up in the menu, as a sub-item of the specified parent? I guess I could use the API to programatically create the link, although I haven't tried it so it might have the same problem, but I want this one in config.

Is the problem maybe that because the Views module declares its links dynamically, I need to do the same for that dynamically created parent to even be available?

3

Views generates menu link id's with a prefix views_view: and the first page display normally has the id page_1, so the parent should be something like this:

  parent: views_view:views.branch_locations.page_1

There is no error thrown, if parent: doesn't match an existing menu link. It's ignored and the menu link appears in the top level of the menu.

It doesn't matter from which provider the menu links are from, all discovered menu links are treated equally in the menu tree table.

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.