You are here

protected function UserCreationTrait::createAdminRole in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/simpletest/src/UserCreationTrait.php \Drupal\simpletest\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.

integer $weight: (optional) The weight for the role. Defaults NULL so that entity_create() 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/simpletest/src/UserCreationTrait.php
Create a user with a given set of permissions.

File

core/modules/simpletest/src/UserCreationTrait.php, line 102
Contains \Drupal\simpletest\UserCreationTrait.

Class

UserCreationTrait
Provides methods to create additional test users and switch the currently logged in one.

Namespace

Drupal\simpletest

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;
}