public function MembershipManager::isMember in Organic groups 8
Returns whether a user belongs to a group.
Parameters
\Drupal\Core\Entity\EntityInterface $group: The group entity.
int $user_id: The ID of 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 entity (e.g. the user or node) belongs to a group with a certain state.
Overrides MembershipManagerInterface::isMember
2 calls to MembershipManager::isMember()
- MembershipManager::isMemberBlocked in src/
MembershipManager.php - Returns whether an entity belongs to a group with a blocked status.
- MembershipManager::isMemberPending in src/
MembershipManager.php - Returns whether a user belongs to a group with a pending status.
File
- src/
MembershipManager.php, line 415
Class
- MembershipManager
- Service for managing memberships and group content.
Namespace
Drupal\ogCode
public function isMember(EntityInterface $group, $user_id, array $states = [
OgMembershipInterface::STATE_ACTIVE,
]) {
if ($user_id instanceof AccountInterface) {
trigger_error('Passing an account object is deprecated in og:8.1.0-alpha4 and is removed from og:8.1.0-beta1. Instead pass the user ID as an integer value. See https://github.com/Gizra/og/issues/542', E_USER_DEPRECATED);
$user_id = $user_id
->id();
}
$group_ids = $this
->getUserGroupIds($user_id, $states);
$entity_type_id = $group
->getEntityTypeId();
return !empty($group_ids[$entity_type_id]) && in_array($group
->id(), $group_ids[$entity_type_id]);
}