public function MembershipManager::getUserGroupsByRoleIds in Organic groups 8
Returns an array of groups filtered by the OG roles of the user.
Parameters
int $user_id: The ID of the user to get the groups for.
string[] $role_ids: A list of OG role IDs to filter by.
string[] $states: (optional) An array of states to filter the memberships by.
bool $require_all_roles: (optional) If set to TRUE, all requested roles must be present to return the group. Set to FALSE to return the groups that match one or more of the requested roles. Defaults to TRUE.
Return value
\Drupal\Core\Entity\ContentEntityInterface[][] An associative array, keyed by group entity type, each item an array of group entities.
Overrides MembershipManagerInterface::getUserGroupsByRoleIds
File
- src/
MembershipManager.php, line 171
Class
- MembershipManager
- Service for managing memberships and group content.
Namespace
Drupal\ogCode
public function getUserGroupsByRoleIds($user_id, array $role_ids, array $states = [
OgMembershipInterface::STATE_ACTIVE,
], bool $require_all_roles = TRUE) : array {
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
->getUserGroupIdsByRoleIds($user_id, $role_ids, $states, $require_all_roles);
return $this
->loadGroups($group_ids);
}