src/Controller/Api/PageController.php
public function postPageBlockAction($id, Request $request)
    {
        $page = $id ? $this->getPage($id) : null;

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

        $form->handleRequest($request);

        if ($form->isValid()) {
            $block = $form->getData();
            $block->setPage($page);

            $this->blockManager->save($block);

            return $block;
        }

        return $form;
    }
public function postPageBlockAction($id, Request $request)
    {
        $page = $id ? $this->getPage($id) : null;

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

        $form->handleRequest($request);

        if ($form->isValid()) {
            $block = $form->getData();
            $block->setPage($page);

            $this->blockManager->save($block);

            return $block;
        }

        return $form;
    }
public function postPageBlockAction ( $ id , Request $ request ) { $ page = $ id ? $ this -> getPage ( $ id ) : null ; $ form = $ this -> formFactory -> createNamed ( null , 'sonata_page_api_form_block' , null , [ 'csrf_protection' => false , ] ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isValid ( ) ) { $ block = $ form -> getData ( ) ; $ block -> setPage ( $ page ) ; $ this -> blockManager -> save ( $ block ) ; return $ block ; } return $ form ; }
Adds a block.

@ApiDoc(
requirements={
{"name"="id", "dataType"="integer", "requirement"="\d+", "description"="page identifier"}
},
input={"class"="sonata_page_api_form_block", "name"="", "groups"={"sonata_api_write"}},
output={"class"="Sonata\PageBundle\Model\Block", "groups"={"sonata_api_read"}},
statusCodes={
200="Returned when successful",
400="Returned when an error has occurred while block creation",
404="Returned when unable to find page"
}
)

@View(serializerGroups={"sonata_api_read"}, serializerEnableMaxDepthChecks=true)

@param int     $id      A Page identifier
@param Request $request A Symfony request

@throws NotFoundHttpException

@return BlockInterface
Adds a block .