0

Let's say I want to add an additional link to the admin toolbar after Reports such as Groups does.

In my_module.routing.yml I have:

my_module.admin:
  path: '/admin/my_module'
  defaults:
    _controller: '\Drupal\system\Controller\SystemController::systemAdminMenuBlockPage'
    _title: 'My Module Stuff'
  requirements:
    _permission: 'access administration pages'

In my_module.links.menu.yml I have:

my_module.admin:
  title: My Link
  route_name: 'my_module.admin'
  parent: 'system.admin'
  description: 'Stuff my link does'
  weight: 8

I took these from the corresponding Groups module. When I clear cache, nothing new shows up in the admin toolbar or the admin menu UI settings.

1 Answer 1

1

This does actually work. I created a brand new module and copied your code into those files and it worked - I got the My Link menu appearing in the admin toolbar. I can only think that you don't have the correct permissions for the user you were testing with or that you didn't do a full cache clear (drush cr).

3
  • 1
    It was something similar. You’re correct that the code is right so it had to be config related. In my case I changed the route permission to the role but forgot to change the key itself to role.
    – JAyenGreen
    Jul 11 at 13:55
  • This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review
    – cilefen
    Jul 13 at 10:05
  • @cliefen It does. I pointed out that the code works but that the permissions for the route needed checking (which turned out to be the issue). If someone else has the same problem my response would have given them the knowledge that this code works and that the permissions needed checking.
    – Toby
    Jul 14 at 12:03

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.