You are here

public static function Og::getMemberships in Organic groups 8

Returns the group memberships a user is associated with.

Parameters

\Drupal\Core\Session\AccountInterface $user: The user to get groups for.

array $states: (optional) Array with the states to return. Defaults to only returning active memberships. In order to retrieve all memberships regardless of state, pass `OgMembershipInterface::ALL_STATES`.

Return value

\Drupal\og\OgMembershipInterface[] An array of OgMembership entities, keyed by ID.

1 call to Og::getMemberships()
GetMembershipsTest::testGetMemberships in tests/src/Kernel/Entity/GetMembershipsTest.php
Tests retrieval of OG Membership entities associated with a given user.

File

src/Og.php, line 145

Class

Og
A static helper class for OG.

Namespace

Drupal\og

Code

public static function getMemberships(AccountInterface $user, array $states = [
  OgMembershipInterface::STATE_ACTIVE,
]) {

  /** @var \Drupal\og\MembershipManagerInterface $membership_manager */
  $membership_manager = \Drupal::service('og.membership_manager');
  return $membership_manager
    ->getMemberships($user
    ->id(), $states);
}