public static function GroupAccessResult::allowedIfHasGroupPermissions in Group 8
Same name and namespace in other branches
- 2.0.x src/Access/GroupAccessResult.php \Drupal\group\Access\GroupAccessResult::allowedIfHasGroupPermissions()
Allows access if the permissions are present, neutral otherwise.
@todo Keep an eye on the following with regard to using the current user:
Parameters
\Drupal\group\Entity\GroupInterface $group: The group for which to check permissions.
\Drupal\Core\Session\AccountInterface $account: The account for which to check permissions.
array $permissions: The permissions to check.
string $conjunction: (optional) 'AND' if all permissions are required, 'OR' in case just one. Defaults to 'AND'.
Return value
\Drupal\Core\Access\AccessResult If the account has the permissions, isAllowed() will be TRUE, otherwise isNeutral() will be TRUE.
4 calls to GroupAccessResult::allowedIfHasGroupPermissions()
- GroupContentAccessControlHandler::combinedPermissionCheck in src/
Plugin/ GroupContentAccessControlHandler.php - Checks the provided permission alongside the admin permission.
- GroupContentAccessControlHandler::entityAccess in src/
Plugin/ GroupContentAccessControlHandler.php - Checks access to an operation on the entity.
- GroupContentAccessControlHandler::relationAccess in src/
Plugin/ GroupContentAccessControlHandler.php - Checks access to an operation on the relation.
- GroupPermissionAccessCheck::access in src/
Access/ GroupPermissionAccessCheck.php - Checks access.
File
- src/
Access/ GroupAccessResult.php, line 57
Class
- GroupAccessResult
- Extends the AccessResult class with group permission checks.
Namespace
Drupal\group\AccessCode
public static function allowedIfHasGroupPermissions(GroupInterface $group, AccountInterface $account, array $permissions, $conjunction = 'AND') {
$access = FALSE;
if ($conjunction == 'AND' && !empty($permissions)) {
$access = TRUE;
foreach ($permissions as $permission) {
if (!$group
->hasPermission($permission, $account)) {
$access = FALSE;
break;
}
}
}
else {
foreach ($permissions as $permission) {
if ($group
->hasPermission($permission, $account)) {
$access = TRUE;
break;
}
}
}
return static::allowedIf($access)
->addCacheContexts([
'user.group_permissions',
]);
}