You are here

protected function UserCreationTrait::grantPermissions in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/simpletest/src/UserCreationTrait.php \Drupal\simpletest\UserCreationTrait::grantPermissions()

Grant permissions to a user role.

Parameters

\Drupal\user\RoleInterface $role: The ID of a user role to alter.

array $permissions: (optional) A list of permission names to grant.

1 call to UserCreationTrait::grantPermissions()
UserCreationTrait::createRole in core/modules/simpletest/src/UserCreationTrait.php
Creates a role with specified permissions.

File

core/modules/simpletest/src/UserCreationTrait.php, line 210
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 grantPermissions(RoleInterface $role, array $permissions) {
  foreach ($permissions as $permission) {
    $role
      ->grantPermission($permission);
  }
  $role
    ->trustData()
    ->save();
}