2

Using Drush 9, I am trying to automate the creation of a role and I need to assign permissions to it. I see that I can use drush role-add-perm to do the assignment itself, but I can't find a command to actually give me the permissions supplied by the enabled modules.

It looks like this was doable in older versions of Drush, but I'm not sure Drush 9 has equivalent commands.

Thanks!

2

You could use drush cim and create a yml for your role like for example

langcode: en
status: true
dependencies: {  }
id: myrole
label: 'My super Role'
weight: 1
is_admin: false
permissions: 
  - 'whatever 1'
  - 'whatever 2'

And if you don't know what perms your module brings, you could use that simple eval code with drush:

drush php-eval '$p = Drupal::service("user.permissions")->getPermissions(); foreach ($p as $k => $x) print $k." : ".$x["provider"]."\n";'
  • And you grep the possible permissions of moduleX from modules/custom/moduleX/moduleX.permissions.yml – Rainer Feike Sep 13 at 15:21

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.