protected function handleWriteAddress($request, $id = null)
    {
        $address = $id ? $this->getAddress($id) : null;

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

        $form->handleRequest($request);

        if ($form->isValid()) {
            $address = $form->getData();
            $this->addressManager->save($address);

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

            // simplify when dropping FOSRest < 2.1
            if (method_exists($context, 'enableMaxDepth')) {
                $context->enableMaxDepth();
            } else {
                $context->setMaxDepth(10);
            }

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

            return $view;
        }

        return $form;
    }
protected function handleWriteAddress($request, $id = null)
    {
        $address = $id ? $this->getAddress($id) : null;

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

        $form->handleRequest($request);

        if ($form->isValid()) {
            $address = $form->getData();
            $this->addressManager->save($address);

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

            // simplify when dropping FOSRest < 2.1
            if (method_exists($context, 'enableMaxDepth')) {
                $context->enableMaxDepth();
            } else {
                $context->setMaxDepth(10);
            }

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

            return $view;
        }

        return $form;
    }
protected function handleWriteAddress ( $ request , $ id = null ) { $ address = $ id ? $ this -> getAddress ( $ id ) : null ; $ form = $ this -> formFactory -> createNamed ( null , 'sonata_customer_api_form_address' , $ address , [ 'csrf_protection' => false , ] ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isValid ( ) ) { $ address = $ form -> getData ( ) ; $ this -> addressManager -> save ( $ address ) ; $ context = new Context ( ) ; $ context -> setGroups ( [ 'sonata_api_read' ] ) ; // simplify when dropping FOSRest < 2.1 if ( method_exists ( $ context , 'enableMaxDepth' ) ) { $ context -> enableMaxDepth ( ) ; } else { $ context -> setMaxDepth ( 10 ) ; } $ view = FOSRestView :: create ( $ address ) ; $ view -> setContext ( $ context ) ; return $ view ; } return $ form ; }
Write an address, this method is used by both POST and PUT action methods.

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

@return \FOS\RestBundle\View\View|FormInterface
Write an address this method is used by both POST and PUT action methods .