protected function assignUserToUserGroups(User $user, array $userGroupObjects)
    {
        $ezUserGroups = [];
        foreach ($userGroupObjects as $userGroup) {
            $userGroup = $this->userGroupManager->createOrUpdate($userGroup);
            if ($userGroup instanceof UserGroupObject) {
                $ezUserGroup = $this->userGroupManager->find($userGroup);
                if ($ezUserGroup) {
                    $ezUserGroups[$ezUserGroup->id] = $ezUserGroup;
                    try {
                        $this->userService->assignUserToUserGroup($user, $ezUserGroup);
                    } catch (InvalidArgumentException $alreadyAssignedException) {
                        // Ignore error about: user already assigned to usergroup.
                    }
                }
            }
        }

        return $ezUserGroups;
    }