function UserCreationTrait::grantPermissions

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

Grant permissions to a user role.

Parameters

\Drupal\user\RoleInterface $role: The user role entity to alter.

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

2 calls to UserCreationTrait::grantPermissions()
SettingsTrayBlockFormTest::doTestBlocks in core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayBlockFormTest.php
Tests opening off-canvas dialog by click blocks and elements in the blocks.
UserCreationTrait::createRole in core/modules/user/tests/src/Traits/UserCreationTrait.php
Creates a role with specified permissions.

File

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

Class

UserCreationTrait
Provides test methods for user creation and authentication.

Namespace

Drupal\Tests\user\Traits

Code

protected function grantPermissions(RoleInterface $role, array $permissions) {
  foreach ($permissions as $permission) {
    $role->grantPermission($permission);
  }
  $role->trustData()
    ->save();
}

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