0

I'm creating a custom module in Drupal 8.4.4. I put several menu links under the Development menu.

scrape.scrape_form:
  title: 'Scrape'
  parent: system.admin_config_development
  route_name: scrape.scrape_form
  description: 'Scrape content from ccad.edu'
  weight: 10

scrape.scrape_images_form:
  title: 'Images Scrape'
  parent: system.admin_config_development
  route_name: scrape.scrape_images_form
  description: 'Scrape images from ccad.edu'
  weight: 20

...

This is working fine, but now that whole menu is getting a bit too long.

I wanted to wrap up all of my links under one 'header' link under the Development menu. I added this at the top of mymodule.links.menu.yml:

scrape.migration:
  title: 'Migration'
  description: 'Migration functions'
  parent: system.admin_config_development
  route:<nolink>
  menu_name: scrape.migration
  route_name: scrape.migration

But when I try to rebuild the cache, I get this error:

The website encountered an unexpected error. Please try again later. Symfony\Component\Routing\Exception\RouteNotFoundException: Route &quot;scrape.migration&quot; does not exist. in Drupal\Core\Routing\RouteProvider->getRouteByName()

How can I make a new, non-navigable parent link under Development, to put my custom links under?

Edit 4k4's comment is correct, but my parent link is very small and greyed out.

scrape.migration:
  title: 'Migration'
  description: 'Migration functions'
  parent: system.admin_config_development
  menu_name: scrape.migration
  route_name: <nolink>

enter image description here

How can I get a full-height, dark-font header link?

  • shouldn't this be route_name: <nolink>? – 4k4 Jan 10 '18 at 20:34
  • @4k4 your comment fixed my error and gave me the link, but there is a further wrinkle. Please see edit. Thank you! – user1359 Jan 10 '18 at 20:55
  • 1
    looks like you do not have a CSS style for a menu item that do not include the markup for a link. – LittleCoding Jan 10 '18 at 21:21
2

Instead of using route_name: <nolink>, I suggest providing a route for the link and e.g. pointing that route to Drupal's default overview page contoller. This should fix your issue and assures the users can click the menu link and get an overview of the available functions (e.g. when re-using your module in a Drupal that has no Admin Toolbar installed):

mymodule.links.menu.yml

scrape.migration:
  title: 'Migration'
  description: 'Migration functions'
  parent: system.admin_config_development
  route_name: scrape.migration

mymodule.routing.yml

scrape.migration:
  path: '/admin/config/development/scrape'
  defaults:
    _controller: '\Drupal\system\Controller\SystemController::overview'
    link_id: 'scrape.migration'
    _title: 'Migration'
  requirements:
    _permission: 'access administration pages'

You might have to adapt the path/permissions accordingly.

  • I have a page, but when I navigate to it, I get "You do not have any administrative items. " – user1359 Feb 28 '18 at 17:55
  • Did you set the parent of your submenu items correctly? They need to be the item using the overview controller. – Mario Steinitz Feb 28 '18 at 20:24
  • This is what I have in my module.links.menu.yml: scrape.migration: title: 'Migration' description: 'Migration functions' parent: system.admin_config_development route_name: scrape.migration weight: 10 scrape.scrape_form: title: 'Scrape Static Pages' parent: scrape.migration route_name: scrape.scrape_form description: 'Scrape static content' weight: 20 – user1359 Feb 28 '18 at 21:53
1

Just thought it would be easier to show a basic example that has both parent and submenu item in the mymodule.links.menu.yml.

Right now both links goto the same place (as I had to pick a default for the parent item, since I didn't have a admin page that lists all my custom links yet ... and also since having "route_name: <nolink>" did not work for the parent menu item even though some peeps said it worked for them [Note: using Drupal 8.6.12]):

mymodule.parent:
  title: 'My MainMenu Link'
  parent: system.admin_config
  description: 'Custom main config menu item under the Admin->Configuration menu.'
  route_name: mymodule.form
  weight: 100

mymodule.parent_child:
  title: 'My Submenu Link'
  parent: mymodule.parent
  description: 'This is the sub-menu item for my custom config form.'
  route_name: mymodule.form
  weight: 101

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.