protected function handleWriteProduct($provider, $request, $id = null)
    {
        $product = $id ? $this->getProduct($id) : null;

        try {
            $manager = $this->productPool->getManager($provider);
        } catch (\RuntimeException $e) {
            throw new NotFoundHttpException($e->getMessage(), $e);
        }

        $form = $this->formFactory->createNamed(null, 'sonata_product_api_form_product', $product, [
            'csrf_protection' => false,
            'data_class' => $manager->getClass(),
            'provider_name' => $provider,
        ]);

        $form->handleRequest($request);

        if ($form->isValid()) {
            $product = $form->getData();
            $product->setDescription($this->formatterPool->transform($product->getDescriptionFormatter(), $product->getRawDescription()));
            $product->setShortDescription($this->formatterPool->transform($product->getShortDescriptionFormatter(), $product->getRawShortDescription()));
            $manager->save($product);

            $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($product);
            $view->setContext($context);

            return $view;
        }

        return $form;
    }
protected function handleWriteProduct($provider, $request, $id = null)
    {
        $product = $id ? $this->getProduct($id) : null;

        try {
            $manager = $this->productPool->getManager($provider);
        } catch (\RuntimeException $e) {
            throw new NotFoundHttpException($e->getMessage(), $e);
        }

        $form = $this->formFactory->createNamed(null, 'sonata_product_api_form_product', $product, [
            'csrf_protection' => false,
            'data_class' => $manager->getClass(),
            'provider_name' => $provider,
        ]);

        $form->handleRequest($request);

        if ($form->isValid()) {
            $product = $form->getData();
            $product->setDescription($this->formatterPool->transform($product->getDescriptionFormatter(), $product->getRawDescription()));
            $product->setShortDescription($this->formatterPool->transform($product->getShortDescriptionFormatter(), $product->getRawShortDescription()));
            $manager->save($product);

            $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($product);
            $view->setContext($context);

            return $view;
        }

        return $form;
    }
protected function handleWriteProduct ( $ provider , $ request , $ id = null ) { $ product = $ id ? $ this -> getProduct ( $ id ) : null ; try { $ manager = $ this -> productPool -> getManager ( $ provider ) ; } catch ( \ RuntimeException $ e ) { throw new NotFoundHttpException ( $ e -> getMessage ( ) , $ e ) ; } $ form = $ this -> formFactory -> createNamed ( null , 'sonata_product_api_form_product' , $ product , [ 'csrf_protection' => false , 'data_class' => $ manager -> getClass ( ) , 'provider_name' => $ provider , ] ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isValid ( ) ) { $ product = $ form -> getData ( ) ; $ product -> setDescription ( $ this -> formatterPool -> transform ( $ product -> getDescriptionFormatter ( ) , $ product -> getRawDescription ( ) ) ) ; $ product -> setShortDescription ( $ this -> formatterPool -> transform ( $ product -> getShortDescriptionFormatter ( ) , $ product -> getRawShortDescription ( ) ) ) ; $ manager -> save ( $ product ) ; $ 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 ( $ product ) ; $ view -> setContext ( $ context ) ; return $ view ; } return $ form ; }
Write a product, this method is used by both POST and PUT action methods.

@param string   $provider A product provider name
@param Request  $request  Symfony request
@param int|null $id       A product identifier

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