function UserCreationTrait::createAdminRole

Same name in other branches
  1. 9 core/modules/user/tests/src/Traits/UserCreationTrait.php \Drupal\Tests\user\Traits\UserCreationTrait::createAdminRole()
  2. 8.9.x core/modules/user/tests/src/Traits/UserCreationTrait.php \Drupal\Tests\user\Traits\UserCreationTrait::createAdminRole()
  3. 10 core/modules/user/tests/src/Traits/UserCreationTrait.php \Drupal\Tests\user\Traits\UserCreationTrait::createAdminRole()

Creates an administrative role.

Parameters

string $rid: (optional) The role ID (machine name). Defaults to a random name.

string $name: (optional) The label for the role. Defaults to a random string.

int $weight: (optional) The weight for the role. Defaults to NULL which sets the weight to maximum + 1.

Return value

string Role ID of newly created role, or FALSE if role creation failed.

1 call to UserCreationTrait::createAdminRole()
UserCreationTrait::createUser in core/modules/user/tests/src/Traits/UserCreationTrait.php
Create a user with a given set of permissions.

File

core/modules/user/tests/src/Traits/UserCreationTrait.php, line 213

Class

UserCreationTrait
Provides test methods for user creation and authentication.

Namespace

Drupal\Tests\user\Traits

Code

protected function createAdminRole($rid = NULL, $name = NULL, $weight = NULL) {
    $rid = $this->createRole([], $rid, $name, $weight);
    if ($rid) {
        
        /** @var \Drupal\user\RoleInterface $role */
        $role = Role::load($rid);
        $role->setIsAdmin(TRUE);
        $role->save();
    }
    return $rid;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.