public static function Og::getMembership in Organic groups 8
Returns the group membership for a given user and group.
Parameters
\Drupal\Core\Entity\EntityInterface $group: The group to get the membership for.
\Drupal\Core\Session\AccountInterface $user: The user to get the membership 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|null The OgMembership entity. NULL will be returned if no membership is available that matches the passed in $states.
4 calls to Og::getMembership()
- OgMembershipRoleReferenceTest::testRoleCreate in tests/
src/ Kernel/ Entity/ OgMembershipRoleReferenceTest.php - Testing OG membership role referencing.
- OgMembershipTest::testMembershipStaticCache in tests/
src/ Kernel/ Entity/ OgMembershipTest.php - Tests getting an ogMembership from the static cache.
- og_entity_insert in ./
og.module - Implements hook_entity_insert().
- SubscriptionController::unsubscribe in src/
Controller/ SubscriptionController.php - Unsubscribe a user from group.
File
- src/
Og.php, line 167
Class
- Og
- A static helper class for OG.
Namespace
Drupal\ogCode
public static function getMembership(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
->getMembership($group, $user
->id(), $states);
}