You are here

public static function Og::isMember in Organic groups 8

Returns whether a user belongs to a group.

Parameters

\Drupal\Core\Entity\EntityInterface $group: The group entity.

\Drupal\Core\Session\AccountInterface $user: The user to test the membership for.

array $states: (optional) Array with the membership states to check the membership. Defaults to active memberships.

Return value

bool TRUE if the user belongs to a group with a certain state.

7 calls to Og::isMember()
GetUserGroupsTest::testIsMemberStates in tests/src/Kernel/Entity/GetUserGroupsTest.php
Tests member methods for states that other groups users are added to.
GetUserGroupsTest::testOtherGroups in tests/src/Kernel/Entity/GetUserGroupsTest.php
Tests other groups users are added to.
GetUserGroupsTest::testOwnerGroupsOnly in tests/src/Kernel/Entity/GetUserGroupsTest.php
Tests group owners have the correct groups.
GroupSubscribeFormatter::viewElements in src/Plugin/Field/FieldFormatter/GroupSubscribeFormatter.php
Builds a renderable array for a field value.
Og::isMemberBlocked in src/Og.php
Returns whether an entity belongs to a group with a blocked status.

... See full list

File

src/Og.php, line 207

Class

Og
A static helper class for OG.

Namespace

Drupal\og

Code

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

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