You are here

public function DefaultGroupPermissionCalculator::calculateOutsiderPermissions in Group 8

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

Calculates the outsider group permissions for an account.

Parameters

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

Return value

\Drupal\group\Access\CalculatedGroupPermissionsInterface An object representing the outsider group permissions.

Overrides GroupPermissionCalculatorBase::calculateOutsiderPermissions

File

src/Access/DefaultGroupPermissionCalculator.php, line 81

Class

DefaultGroupPermissionCalculator
Calculates group permissions for an account.

Namespace

Drupal\group\Access

Code

public function calculateOutsiderPermissions(AccountInterface $account) {
  $calculated_permissions = new RefinableCalculatedGroupPermissions();

  // @todo Introduce group_role_list:audience:outsider cache tag.
  // If a new group type is introduced, we need to recalculate the outsider
  // permissions. Therefore, we need to introduce the group type list cache
  // tag.
  $calculated_permissions
    ->addCacheTags([
    'config:group_type_list',
  ]);

  /** @var \Drupal\group\Entity\GroupTypeInterface $group_type */
  $storage = $this->entityTypeManager
    ->getStorage('group_type');
  foreach ($storage
    ->loadMultiple() as $group_type_id => $group_type) {
    $group_role = $group_type
      ->getOutsiderRole();
    $item = new CalculatedGroupPermissionsItem(CalculatedGroupPermissionsItemInterface::SCOPE_GROUP_TYPE, $group_type_id, $group_role
      ->getPermissions());
    $calculated_permissions
      ->addItem($item);
    $calculated_permissions
      ->addCacheableDependency($group_role);
  }
  return $calculated_permissions;
}