You are here

public function GroupPermissionChecker::hasPermissionInGroup in Group 8

Same name and namespace in other branches
  1. 2.0.x src/Access/GroupPermissionChecker.php \Drupal\group\Access\GroupPermissionChecker::hasPermissionInGroup()

Checks whether an account has a permission in a group.

Parameters

string $permission: The name of the permission to check for.

\Drupal\Core\Session\AccountInterface $account: The user account for which to check the group permissions.

\Drupal\group\Entity\GroupInterface $group: The group to check the permission against.

Return value

bool Whether the account has the group permission.

Overrides GroupPermissionCheckerInterface::hasPermissionInGroup

File

src/Access/GroupPermissionChecker.php, line 33

Class

GroupPermissionChecker
Calculates group permissions for an account.

Namespace

Drupal\group\Access

Code

public function hasPermissionInGroup($permission, AccountInterface $account, GroupInterface $group) {

  // If the account can bypass all group access, return immediately.
  if ($account
    ->hasPermission('bypass group access')) {
    return TRUE;
  }
  $calculated_permissions = $this->groupPermissionCalculator
    ->calculatePermissions($account);

  // If the user has member permissions for this group, check those, otherwise
  // we need to check the group type permissions instead, i.e.: the ones for
  // anonymous or outsider audiences.
  $item = $calculated_permissions
    ->getItem(CalculatedGroupPermissionsItemInterface::SCOPE_GROUP, $group
    ->id());
  if ($item === FALSE) {
    $item = $calculated_permissions
      ->getItem(CalculatedGroupPermissionsItemInterface::SCOPE_GROUP_TYPE, $group
      ->bundle());
  }
  return $item
    ->hasPermission($permission);
}