You are here

public function MembershipManager::getGroups in Organic groups 8

Returns all groups that are associated with the given group content entity.

Do not use this to retrieve group memberships for a user entity. Use GroupMembershipInterface::getUserGroups() instead.

The reason there are separate method for group content and user entities is because the storage is handled differently. For group content the relation to the group is stored on a field attached to the content entity, while user memberships are tracked in OgMembership entities.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The group content entity for which to return the groups.

string $group_type_id: Filter results to only include groups of this entity type.

string $group_bundle: Filter results to only include groups of this bundle.

Return value

\Drupal\Core\Entity\EntityInterface[][] An associative array, keyed by group entity type, each item an array of group entities.

Overrides MembershipManagerInterface::getGroups

See also

\Drupal\og\GroupMembershipInterface::getUserGroups()

File

src/MembershipManager.php, line 350

Class

MembershipManager
Service for managing memberships and group content.

Namespace

Drupal\og

Code

public function getGroups(EntityInterface $entity, $group_type_id = NULL, $group_bundle = NULL) {
  $group_ids = $this
    ->getGroupIds($entity, $group_type_id, $group_bundle);
  return $this
    ->loadGroups($group_ids);
}