Skip to main content
4 of 5
edited title
Adrian Cid Almaguer
  • 18.5k
  • 14
  • 79
  • 133

How to get user permissions for the role Administrator?

I need to get permissions for all user roles, which are used. The code looks something like this:

$anonymous = Role::load('anonymous');
$anonymousPermissions = $anonymous->getPermissions();

The code for anonymous (and also for authenticated) returns an array of permissions, but the same code for administrator returns null:

$administrator = Role::load('administrator');

How can I get permissions for the role Administrator? (The machine name of role Administrator is administrator and also in the database is nothing suspicious.)


I have tried also:

$anonymousPermissions = user_role_permissions(['administrator']);

It returns:

array(1) {
    ["administrator"] =>
        array(0) {
    }
}

If I try:

$roles = Role::loadMultiple();
foreach ($roles as $role => $rolesObj) {
    $role_list[$role] = $rolesObj->get('label');
}
print_r($role_list);

Then I get:

Array
(
    [anonymous] => Anonymous user
    [authenticated] => Authenticated user
)