0

Really simple, where I can I look up the custom roles and their role id's?

2 Answers 2

1

On the People > Roles (admin/people/roles) page you can hover over the Edit links or click on them to see what the machine-readable name is, that is the role ID.

For example in Drupal 8 you get three Roles built in with these Role IDs: anonymous, authenticated, administrator.

In Drupal 7 you can do the same to look them up, only the path and the wording are a little bit different (People > Permissions > Roles, admin/people/permissions/roles).

In Drupal 8 Role IDs are now machine-readable strings while in Drupal 7 and below they were integers (numbers).

D8

$user->roles = array(
  'authenticated' => 'Authenticated user',
  'administrator' => 'Administrator',
  'site_editor' => 'Site editor',
);

D7

$user->roles = array(
  2 => 'authenticated user',
  3 => 'administrator',
  4 => 'site editor',
);
1

Not what I was looking for, but if you inspect the Roles Drop Drop on the People Page then the array has the ID in it.

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.