function UserCreationTrait::createAdminRole

Same name and namespace in other branches
  1. 11.x core/modules/user/tests/src/Traits/UserCreationTrait.php \Drupal\Tests\user\Traits\UserCreationTrait::createAdminRole()
  2. 10 core/modules/user/tests/src/Traits/UserCreationTrait.php \Drupal\Tests\user\Traits\UserCreationTrait::createAdminRole()
  3. 9 core/modules/user/tests/src/Traits/UserCreationTrait.php \Drupal\Tests\user\Traits\UserCreationTrait::createAdminRole()
  4. 8.9.x 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.

File

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

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) : string {
  $rid = $this->createRole([], $rid, $name, $weight);
  /** @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.