src/Controller/PageAdminController.php
public function translateAction(Request $request, $id, $locale)
    {
        /** @var PageInterface $page */
        $page = $this->admin->getObject($id);

        if (!$page) {
            throw new NotFoundHttpException(sprintf('unable to find the object with id : %s', $id));
        }
        $language = \Locale::getDisplayLanguage($locale);

        if ($request->getMethod() == 'POST') {
            $pageHelper = $this->container->get('networking_init_cms.helper.page_helper');

            try {
                $pageCopy = $pageHelper->makeTranslationCopy($page, $locale);
                $this->admin->createObjectSecurity($pageCopy);
                $status = 'success';
                $message = $this->translate(
                    'message.translation_saved',
                    ['%language%' => $language]
                );
                $result = 'ok';
                $html = $this->renderView(
                    '@NetworkingInitCms/PageAdmin/page_translation_settings.html.twig',
                    ['object' => $page, 'admin' => $this->admin]
                );
            } catch (\Exception $e) {
                $status = 'error';
                $message = $message = $this->translate(
                    'message.translation_not_saved',
                    ['%language%' => $language, '%url%' => $page->getFullPath()]
                );
                $result = 'error';
                $html = '';
            }

            if ($this->isXmlHttpRequest()) {
                return $this->renderJson(
                    [
                        'result' => $result,
                        'status' => $status,
                        'html' => $html,
                        'message' => $message,
                    ]
                );
            }

            $this->get('session')->getFlashBag()->add(
                'sonata_flash_'.$status,
                $message
            );

            return $this->redirect($this->admin->generateUrl('edit', ['id' => $id]));
        }

        return $this->render(
            '@NetworkingInitCms/PageAdmin/page_translation_copy.html.twig',
            [
                'action' => 'copy',
                'page' => $page,
                'id' => $id,
                'locale' => $locale,
                'language' => $language,
                'admin' => $this->admin,
            ]
        );
    }
public function translateAction(Request $request, $id, $locale)
    {
        /** @var PageInterface $page */
        $page = $this->admin->getObject($id);

        if (!$page) {
            throw new NotFoundHttpException(sprintf('unable to find the object with id : %s', $id));
        }
        $language = \Locale::getDisplayLanguage($locale);

        if ($request->getMethod() == 'POST') {
            $pageHelper = $this->container->get('networking_init_cms.helper.page_helper');

            try {
                $pageCopy = $pageHelper->makeTranslationCopy($page, $locale);
                $this->admin->createObjectSecurity($pageCopy);
                $status = 'success';
                $message = $this->translate(
                    'message.translation_saved',
                    ['%language%' => $language]
                );
                $result = 'ok';
                $html = $this->renderView(
                    '@NetworkingInitCms/PageAdmin/page_translation_settings.html.twig',
                    ['object' => $page, 'admin' => $this->admin]
                );
            } catch (\Exception $e) {
                $status = 'error';
                $message = $message = $this->translate(
                    'message.translation_not_saved',
                    ['%language%' => $language, '%url%' => $page->getFullPath()]
                );
                $result = 'error';
                $html = '';
            }

            if ($this->isXmlHttpRequest()) {
                return $this->renderJson(
                    [
                        'result' => $result,
                        'status' => $status,
                        'html' => $html,
                        'message' => $message,
                    ]
                );
            }

            $this->get('session')->getFlashBag()->add(
                'sonata_flash_'.$status,
                $message
            );

            return $this->redirect($this->admin->generateUrl('edit', ['id' => $id]));
        }

        return $this->render(
            '@NetworkingInitCms/PageAdmin/page_translation_copy.html.twig',
            [
                'action' => 'copy',
                'page' => $page,
                'id' => $id,
                'locale' => $locale,
                'language' => $language,
                'admin' => $this->admin,
            ]
        );
    }
public function translateAction ( Request $ request , $ id , $ locale ) { /** @var PageInterface $page */ $ page = $ this -> admin -> getObject ( $ id ) ; if ( ! $ page ) { throw new NotFoundHttpException ( sprintf ( 'unable to find the object with id : %s' , $ id ) ) ; } $ language = \ Locale :: getDisplayLanguage ( $ locale ) ; if ( $ request -> getMethod ( ) == 'POST' ) { $ pageHelper = $ this -> container -> get ( 'networking_init_cms.helper.page_helper' ) ; try { $ pageCopy = $ pageHelper -> makeTranslationCopy ( $ page , $ locale ) ; $ this -> admin -> createObjectSecurity ( $ pageCopy ) ; $ status = 'success' ; $ message = $ this -> translate ( 'message.translation_saved' , [ '%language%' => $ language ] ) ; $ result = 'ok' ; $ html = $ this -> renderView ( '@NetworkingInitCms/PageAdmin/page_translation_settings.html.twig' , [ 'object' => $ page , 'admin' => $ this -> admin ] ) ; } catch ( \ Exception $ e ) { $ status = 'error' ; $ message = $ message = $ this -> translate ( 'message.translation_not_saved' , [ '%language%' => $ language , '%url%' => $ page -> getFullPath ( ) ] ) ; $ result = 'error' ; $ html = '' ; } if ( $ this -> isXmlHttpRequest ( ) ) { return $ this -> renderJson ( [ 'result' => $ result , 'status' => $ status , 'html' => $ html , 'message' => $ message , ] ) ; } $ this -> get ( 'session' ) -> getFlashBag ( ) -> add ( 'sonata_flash_' . $ status , $ message ) ; return $ this -> redirect ( $ this -> admin -> generateUrl ( 'edit' , [ 'id' => $ id ] ) ) ; } return $ this -> render ( '@NetworkingInitCms/PageAdmin/page_translation_copy.html.twig' , [ 'action' => 'copy' , 'page' => $ page , 'id' => $ id , 'locale' => $ locale , 'language' => $ language , 'admin' => $ this -> admin , ] ) ; }
Create a copy of a page in the given local and connect the pages.

@param Request $request
@param $id
@param $locale

@return RedirectResponse|Response

@throws NotFoundHttpException
Create a copy of a page in the given local and connect the pages .