RoleStorage::isPermissionInRoles

public RoleStorage::isPermissionInRoles($permission, array $rids)

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

1
2
3
4
5
6
7
8
9
10
11
12
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;
}
doc_Drupal
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.