You are here

protected function FlagPermissionsTrait::grantFlagPermissions in Flag 8.4

Grants flag and unflag permission to the given flag.

Parameters

\Drupal\flag\FlagInterface $flag: The flag on which to grant permissions.

array|string $role_id: (optional) The ID of the role to grant permissions. If omitted, the authenticated role is assumed.

bool $can_flag: (optional) TRUE to grant the role flagging permission, FALSE to not grant flagging permission to the role. If omitted, TRUE is assumed.

bool $can_unflag: Optional TRUE to grant the role unflagging permission, FALSE to not grant unflagging permission to the role. If omitted, TRUE is assumed.

13 calls to FlagPermissionsTrait::grantFlagPermissions()
AdminUITest::doFlagAdd in tests/src/Functional/AdminUITest.php
Flag creation.
AjaxLinkNoJsTest::setUp in tests/src/Functional/AjaxLinkNoJsTest.php
AjaxLinkTest::setUp in tests/src/FunctionalJavascript/AjaxLinkTest.php
FlagContextualLinksTest::setUp in tests/src/FunctionalJavascript/FlagContextualLinksTest.php
LinkHtmlTest::doFlagNode in tests/src/Functional/LinkHtmlTest.php
Flag a node and check flag text.

... See full list

File

tests/src/Traits/FlagPermissionsTrait.php, line 29

Class

FlagPermissionsTrait
Trait for programmatically creating Flags.

Namespace

Drupal\Tests\flag\Traits

Code

protected function grantFlagPermissions(FlagInterface $flag, $role_id = RoleInterface::AUTHENTICATED_ID, $can_flag = TRUE, $can_unflag = TRUE) {

  // Grant the flag permissions to the authenticated role, so that both
  // users have the same roles and share the render cache.
  $role = Role::load($role_id);
  if ($can_flag) {
    $role
      ->grantPermission('flag ' . $flag
      ->id());
  }
  if ($can_unflag) {
    $role
      ->grantPermission('unflag ' . $flag
      ->id());
  }
  $role
    ->grantPermission('access contextual links');
  $role
    ->save();
}