3

I want to assign multiple roles in my routing.yml file :

requirements: _role: "['role1', 'role2', 'role3']"

This is what I currently have, and it doesn't work.

Can someone tell me how to add this?

Thanks in advance!

1
  • use permissions, not roles.
    – sonfd
    Commented Jul 28, 2021 at 14:54

1 Answer 1

11

I would strongly advise using permissions, not roles. Permissions are super simple to create in D8+, see How do you create a custom permission to administer a custom module?

The Structure of routes documentation says:

_role: A specific Drupal role, for example 'administrator'. You can specify multiple ones via "," for AND and "+" for OR logic.

For example, _role: organizer,participant,controller means a Drupal user needs to have all three roles to access the page. Note that, since the roles available may differ between sites, it's recommended to use permission-based access restriction when possible.

So if a user needs all three roles, it's:

_role: 'role1,role2,role3'

or if they just need one of the three roles, it's:

_role: 'role1+role2+role3'
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.