protected function UserCreationTrait::createAdminRole in Drupal 9
Same name and namespace in other branches
- 8 core/modules/user/tests/src/Traits/UserCreationTrait.php \Drupal\Tests\user\Traits\UserCreationTrait::createAdminRole()
- 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 221
Class
- UserCreationTrait
- Provides methods to create additional test users and switch the currently logged in one.
Namespace
Drupal\Tests\user\TraitsCode
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;
}