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?