You are here

public function DefaultGroupPermissionCalculator::calculateAnonymousPermissions in Group 2.0.x

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

Calculates the anonymous group permissions.

Return value

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

Overrides GroupPermissionCalculatorBase::calculateAnonymousPermissions

File

src/Access/DefaultGroupPermissionCalculator.php, line 51

Class

DefaultGroupPermissionCalculator
Calculates group permissions for an account.

Namespace

Drupal\group\Access

Code

public function calculateAnonymousPermissions() {
  $calculated_permissions = new RefinableCalculatedGroupPermissions();

  // @todo Introduce group_role_list:audience:anonymous cache tag.
  // If a new group type is introduced, we need to recalculate the anonymous
  // permissions hash. 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
      ->getAnonymousRole();
    $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;
}