You are here

public function RoleStorage::isPermissionInRoles in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/user/src/RoleStorage.php \Drupal\user\RoleStorage::isPermissionInRoles()

Returns whether a permission is in one of the passed in roles.

Parameters

string $permission: The permission.

array $rids: The list of role IDs to check.

Return value

bool TRUE is the permission is in at least one of the roles. FALSE otherwise.

Overrides RoleStorageInterface::isPermissionInRoles

File

core/modules/user/src/RoleStorage.php, line 15

Class

RoleStorage
Controller class for user roles.

Namespace

Drupal\user

Code

public function isPermissionInRoles($permission, array $rids) {
  $has_permission = FALSE;
  foreach ($this
    ->loadMultiple($rids) as $role) {

    /** @var \Drupal\user\RoleInterface $role */
    if ($role
      ->isAdmin() || $role
      ->hasPermission($permission)) {
      $has_permission = TRUE;
      break;
    }
  }
  return $has_permission;
}