Score:2

Need to add multiple roles to routing.yml file

us flag

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!

sonfd avatar
in flag
use permissions, not roles.
Score:5
in flag

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 or 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'
metalac avatar
us flag
It works! Thanks a lot guys!
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.