protected function handleWriteUser($request, $id = null)
    {
        $user = $id ? $this->getUser($id) : null;

        $form = $this->formFactory->createNamed(null, 'sonata_user_api_form_user', $user, [
            'csrf_protection' => false,
        ]);

        $form->handleRequest($request);

        if ($form->isValid()) {
            $user = $form->getData();
            $this->userManager->updateUser($user);

            $context = new Context();
            $context->setGroups(['sonata_api_read']);
            $context->enableMaxDepth();

            $view = FOSRestView::create($user);
            $view->setContext($context);

            return $view;
        }

        return $form;
    }
protected function handleWriteUser($request, $id = null)
    {
        $user = $id ? $this->getUser($id) : null;

        $form = $this->formFactory->createNamed(null, 'sonata_user_api_form_user', $user, [
            'csrf_protection' => false,
        ]);

        $form->handleRequest($request);

        if ($form->isValid()) {
            $user = $form->getData();
            $this->userManager->updateUser($user);

            $context = new Context();
            $context->setGroups(['sonata_api_read']);
            $context->enableMaxDepth();

            $view = FOSRestView::create($user);
            $view->setContext($context);

            return $view;
        }

        return $form;
    }
protected function handleWriteUser ( $ request , $ id = null ) { $ user = $ id ? $ this -> getUser ( $ id ) : null ; $ form = $ this -> formFactory -> createNamed ( null , 'sonata_user_api_form_user' , $ user , [ 'csrf_protection' => false , ] ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isValid ( ) ) { $ user = $ form -> getData ( ) ; $ this -> userManager -> updateUser ( $ user ) ; $ context = new Context ( ) ; $ context -> setGroups ( [ 'sonata_api_read' ] ) ; $ context -> enableMaxDepth ( ) ; $ view = FOSRestView :: create ( $ user ) ; $ view -> setContext ( $ context ) ; return $ view ; } return $ form ; }
Write an User, this method is used by both POST and PUT action methods.

@param Request  $request Symfony request
@param int|null $id      An User identifier

@return FormInterface
Write an User this method is used by both POST and PUT action methods .