src/Controller/Api/MediaController.php
protected function handleWriteMedium(Request $request, MediaInterface $media, MediaProviderInterface $provider)
    {
        $form = $this->formFactory->createNamed(null, 'sonata_media_api_form_media', $media, [
            'provider_name' => $provider->getName(),
            'csrf_protection' => false,
        ]);

        $form->handleRequest($request);

        if ($form->isValid()) {
            $media = $form->getData();
            $this->mediaManager->save($media);

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

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

            return $view;
        }

        return $form;
    }
protected function handleWriteMedium(Request $request, MediaInterface $media, MediaProviderInterface $provider)
    {
        $form = $this->formFactory->createNamed(null, 'sonata_media_api_form_media', $media, [
            'provider_name' => $provider->getName(),
            'csrf_protection' => false,
        ]);

        $form->handleRequest($request);

        if ($form->isValid()) {
            $media = $form->getData();
            $this->mediaManager->save($media);

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

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

            return $view;
        }

        return $form;
    }
protected function handleWriteMedium ( Request $ request , MediaInterface $ media , MediaProviderInterface $ provider ) { $ form = $ this -> formFactory -> createNamed ( null , 'sonata_media_api_form_media' , $ media , [ 'provider_name' => $ provider -> getName ( ) , 'csrf_protection' => false , ] ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isValid ( ) ) { $ media = $ form -> getData ( ) ; $ this -> mediaManager -> save ( $ media ) ; $ context = new Context ( ) ; $ context -> setGroups ( [ 'sonata_api_read' ] ) ; $ context -> enableMaxDepth ( ) ; $ view = FOSRestView :: create ( $ media ) ; $ view -> setContext ( $ context ) ; return $ view ; } return $ form ; }
Write a medium, this method is used by both POST and PUT action methods.

@param Request                $request
@param MediaInterface         $media
@param MediaProviderInterface $provider

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