class GroupPermissionChecker in Group 8
Same name and namespace in other branches
- 2.0.x src/Access/GroupPermissionChecker.php \Drupal\group\Access\GroupPermissionChecker
Calculates group permissions for an account.
Hierarchy
- class \Drupal\group\Access\GroupPermissionChecker implements GroupPermissionCheckerInterface
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'
1 service uses GroupPermissionChecker
File
- src/
Access/ GroupPermissionChecker.php, line 11
Namespace
Drupal\group\AccessView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
GroupPermissionChecker:: |
protected | property | The group permission calculator. | |
GroupPermissionChecker:: |
public | function |
Checks whether an account has a permission in a group. Overrides GroupPermissionCheckerInterface:: |
|
GroupPermissionChecker:: |
public | function | Constructs a GroupPermissionChecker object. |