You are here

public function UserGroupAccessResolver::resolve in Organic groups 8

Resolves groups within the plugin's domain.

Parameters

\Drupal\og\OgResolvedGroupCollectionInterface $collection: A collection of groups that were resolved by previous plugins. If the plugin discovers new groups, it may add these to this collection. A plugin may also remove groups from the collection that were previously discovered by other plugins, if it finds out that certain groups are incompatible with the current state in the plugin's domain.

Overrides OgGroupResolverInterface::resolve

File

src/Plugin/OgGroupResolver/UserGroupAccessResolver.php, line 28

Class

UserGroupAccessResolver
Checks that the current user has access to the resolved groups.

Namespace

Drupal\og\Plugin\OgGroupResolver

Code

public function resolve(OgResolvedGroupCollectionInterface $collection) {
  foreach ($collection
    ->getGroupInfo() as $group_info) {

    /** @var \Drupal\Core\Entity\ContentEntityInterface $group */
    $group = $group_info['entity'];

    // If the current user has access, cast a vote along with the 'user'
    // cache context, since the current user affects the outcome of the final
    // result.
    if ($group
      ->access('view')) {
      $collection
        ->addGroup($group, [
        'user',
      ]);
    }
    else {

      // The user doesn't have access. Remove the group from the collection.
      $collection
        ->removeGroup($group);
    }
  }
}