public function cloneAction(Page $source, Page $parent = null, $sibling = null, Request $request)
    {
        // user must have view permission on chosen layout
        $this->granted('VIEW', $source->getLayout());

        if (null !== $sibling) {
            $parent = $sibling->getParent();
        } elseif (null === $parent) {
            $parent = $source->getParent();
        }

        if (null !== $parent) {
            $this->granted('EDIT', $parent);
        } else {
            $this->granted('EDIT', $this->getApplication()->getSite());
        }

        $page = $this->getPageRepository()->duplicate(
            $source,
            $request->request->get('title'),
            $parent,
            true,
            $this->getApplication()->getBBUserToken()
        );

        $this->getApplication()->getEntityManager()->persist($page);
        $this->getApplication()->getEntityManager()->flush();

        if (null !== $sibling) {
            $this->getPageRepository()->moveAsPrevSiblingOf($page, $sibling);
        }

        return $this->createJsonResponse(null, 201, [
            'Location' => $this->getApplication()->getRouting()->getUrlByRouteName(
                'bb.rest.page.get',
                [
                    'version' => $request->attributes->get('version'),
                    'uid'     => $page->getUid(),
                ],
                '',
                false
            ),
            'BB-PAGE-URL' => $page->getUrl()
        ]);
    }
public function cloneAction(Page $source, Page $parent = null, $sibling = null, Request $request)
    {
        // user must have view permission on chosen layout
        $this->granted('VIEW', $source->getLayout());

        if (null !== $sibling) {
            $parent = $sibling->getParent();
        } elseif (null === $parent) {
            $parent = $source->getParent();
        }

        if (null !== $parent) {
            $this->granted('EDIT', $parent);
        } else {
            $this->granted('EDIT', $this->getApplication()->getSite());
        }

        $page = $this->getPageRepository()->duplicate(
            $source,
            $request->request->get('title'),
            $parent,
            true,
            $this->getApplication()->getBBUserToken()
        );

        $this->getApplication()->getEntityManager()->persist($page);
        $this->getApplication()->getEntityManager()->flush();

        if (null !== $sibling) {
            $this->getPageRepository()->moveAsPrevSiblingOf($page, $sibling);
        }

        return $this->createJsonResponse(null, 201, [
            'Location' => $this->getApplication()->getRouting()->getUrlByRouteName(
                'bb.rest.page.get',
                [
                    'version' => $request->attributes->get('version'),
                    'uid'     => $page->getUid(),
                ],
                '',
                false
            ),
            'BB-PAGE-URL' => $page->getUrl()
        ]);
    }
public function cloneAction ( Page $ source , Page $ parent = null , $ sibling = null , Request $ request ) { // user must have view permission on chosen layout $ this -> granted ( 'VIEW' , $ source -> getLayout ( ) ) ; if ( null !== $ sibling ) { $ parent = $ sibling -> getParent ( ) ; } elseif ( null === $ parent ) { $ parent = $ source -> getParent ( ) ; } if ( null !== $ parent ) { $ this -> granted ( 'EDIT' , $ parent ) ; } else { $ this -> granted ( 'EDIT' , $ this -> getApplication ( ) -> getSite ( ) ) ; } $ page = $ this -> getPageRepository ( ) -> duplicate ( $ source , $ request -> request -> get ( 'title' ) , $ parent , true , $ this -> getApplication ( ) -> getBBUserToken ( ) ) ; $ this -> getApplication ( ) -> getEntityManager ( ) -> persist ( $ page ) ; $ this -> getApplication ( ) -> getEntityManager ( ) -> flush ( ) ; if ( null !== $ sibling ) { $ this -> getPageRepository ( ) -> moveAsPrevSiblingOf ( $ page , $ sibling ) ; } return $ this -> createJsonResponse ( null , 201 , [ 'Location' => $ this -> getApplication ( ) -> getRouting ( ) -> getUrlByRouteName ( 'bb.rest.page.get' , [ 'version' => $ request -> attributes -> get ( 'version' ) , 'uid' => $ page -> getUid ( ) , ] , '' , false ) , 'BB-PAGE-URL' => $ page -> getUrl ( ) ] ) ; }
Clone a page.

@return \Symfony\Component\HttpFoundation\Response

@Rest\RequestParam(name="title", description="Cloning page new title", requirements={
@Assert\Length(min=3, minMessage="Title must contains atleast 3 characters"),
@Assert\NotBlank
})

@Rest\ParamConverter(name="source", class="BackBee\NestedNode\Page")
@Rest\ParamConverter(
name="parent", id_name="parent_uid", id_source="request", class="BackBee\NestedNode\Page", required=false
)
@Rest\ParamConverter(
name="sibling", id_name="sibling_uid", id_source="request", class="BackBee\NestedNode\Page", required=false
)

@Rest\Security(expression="is_granted('CREATE', source)")
Clone a page .