public function deleteUserGroupAction($userId, $groupId)
    {
        $user = $this->getUser($userId);
        $group = $this->getGroup($groupId);

        if (!$user->hasGroup($group)) {
            return FOSRestView::create([
                'error' => sprintf('User "%s" has not group "%s"', $userId, $groupId),
            ], 400);
        }

        $user->removeGroup($group);
        $this->userManager->updateUser($user);

        return ['removed' => true];
    }
public function deleteUserGroupAction($userId, $groupId)
    {
        $user = $this->getUser($userId);
        $group = $this->getGroup($groupId);

        if (!$user->hasGroup($group)) {
            return FOSRestView::create([
                'error' => sprintf('User "%s" has not group "%s"', $userId, $groupId),
            ], 400);
        }

        $user->removeGroup($group);
        $this->userManager->updateUser($user);

        return ['removed' => true];
    }
public function deleteUserGroupAction ( $ userId , $ groupId ) { $ user = $ this -> getUser ( $ userId ) ; $ group = $ this -> getGroup ( $ groupId ) ; if ( ! $ user -> hasGroup ( $ group ) ) { return FOSRestView :: create ( [ 'error' => sprintf ( 'User "%s" has not group "%s"' , $ userId , $ groupId ) , ] , 400 ) ; } $ user -> removeGroup ( $ group ) ; $ this -> userManager -> updateUser ( $ user ) ; return [ 'removed' => true ] ; }
Detach a group to a user.

@ApiDoc(
requirements={
{"name"="userId", "dataType"="integer", "requirement"="\d+", "description"="user identifier"},
{"name"="groupId", "dataType"="integer", "requirement"="\d+", "description"="group identifier"}
},
output={"class"="Sonata\UserBundle\Model\User", "groups"={"sonata_api_read"}},
statusCodes={
200="Returned when successful",
400="Returned when an error has occurred while user/group detachment",
404="Returned when unable to find user or group"
}
)

@param int $userId  A User identifier
@param int $groupId A Group identifier

@throws NotFoundHttpException
@throws \RuntimeException

@return UserInterface
Detach a group to a user .