src/Controller/Api/GalleryController.php
protected function handleWriteGallery($request, $id = null)
    {
        $gallery = $id ? $this->getGallery($id) : null;

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

        $form->handleRequest($request);

        if ($form->isValid()) {
            $gallery = $form->getData();
            $this->galleryManager->save($gallery);

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

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

            return $view;
        }

        return $form;
    }
protected function handleWriteGallery($request, $id = null)
    {
        $gallery = $id ? $this->getGallery($id) : null;

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

        $form->handleRequest($request);

        if ($form->isValid()) {
            $gallery = $form->getData();
            $this->galleryManager->save($gallery);

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

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

            return $view;
        }

        return $form;
    }
protected function handleWriteGallery ( $ request , $ id = null ) { $ gallery = $ id ? $ this -> getGallery ( $ id ) : null ; $ form = $ this -> formFactory -> createNamed ( null , 'sonata_media_api_form_gallery' , $ gallery , [ 'csrf_protection' => false , ] ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isValid ( ) ) { $ gallery = $ form -> getData ( ) ; $ this -> galleryManager -> save ( $ gallery ) ; $ context = new Context ( ) ; $ context -> setGroups ( [ 'sonata_api_read' ] ) ; $ context -> enableMaxDepth ( ) ; $ view = FOSRestView :: create ( $ gallery ) ; $ view -> setContext ( $ context ) ; return $ view ; } return $ form ; }
Write a Gallery, this method is used by both POST and PUT action methods.

@param Request  $request Symfony request
@param int|null $id      A Gallery identifier

@return View|FormInterface
Write a Gallery this method is used by both POST and PUT action methods .