You are here

class GroupPermissionChecker in Group 8

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

Calculates group permissions for an account.

Hierarchy

Expanded class hierarchy of GroupPermissionChecker

1 file declares its use of GroupPermissionChecker
GroupPermissionCheckerTest.php in tests/src/Unit/GroupPermissionCheckerTest.php
1 string reference to 'GroupPermissionChecker'
group.services.yml in ./group.services.yml
group.services.yml
1 service uses GroupPermissionChecker
group_permission.checker in ./group.services.yml
Drupal\group\Access\GroupPermissionChecker

File

src/Access/GroupPermissionChecker.php, line 11

Namespace

Drupal\group\Access
View source
class GroupPermissionChecker implements GroupPermissionCheckerInterface {

  /**
   * The group permission calculator.
   *
   * @var \Drupal\group\Access\ChainGroupPermissionCalculatorInterface
   */
  protected $groupPermissionCalculator;

  /**
   * Constructs a GroupPermissionChecker object.
   *
   * @param \Drupal\group\Access\ChainGroupPermissionCalculatorInterface $permission_calculator
   *   The group permission calculator.
   */
  public function __construct(ChainGroupPermissionCalculatorInterface $permission_calculator) {
    $this->groupPermissionCalculator = $permission_calculator;
  }

  /**
   * {@inheritdoc}
   */
  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);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
GroupPermissionChecker::$groupPermissionCalculator protected property The group permission calculator.
GroupPermissionChecker::hasPermissionInGroup public function Checks whether an account has a permission in a group. Overrides GroupPermissionCheckerInterface::hasPermissionInGroup
GroupPermissionChecker::__construct public function Constructs a GroupPermissionChecker object.