Networking\InitCmsBundle\Controller\PageAdminController::translatePageAction PHP Méthode

translatePageAction() public méthode

Create a copy of a page in the given local and connect the pages
public translatePageAction ( Request $request, $id, $locale ) : RedirectResponse | Response
$request Symfony\Component\HttpFoundation\Request
$id
$locale
Résultat Symfony\Component\HttpFoundation\RedirectResponse | Symfony\Component\HttpFoundation\Response
    public function translatePageAction(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', array('%language%' => $language));
                $result = 'ok';
                $html = $this->renderView('NetworkingInitCmsBundle:PageAdmin:page_translation_settings.html.twig', array('object' => $page, 'admin' => $this->admin));
            } catch (\Exception $e) {
                $status = 'error';
                $message = $message = $this->translate('message.translation_not_saved', array('%language%' => $language, '%url%' => $page->getFullPath()));
                $result = 'error';
                $html = '';
            }
            if ($this->isXmlHttpRequest()) {
                return $this->renderJson(array('result' => $result, 'status' => $status, 'html' => $html, 'message' => $message));
            }
            $this->get('session')->getFlashBag()->add('sonata_flash_' . $status, $message);
            return $this->redirect($this->admin->generateUrl('edit', array('id' => $id)));
        }
        return $this->render('NetworkingInitCmsBundle:PageAdmin:page_translation_copy.html.twig', array('action' => 'copy', 'page' => $page, 'id' => $id, 'locale' => $locale, 'language' => $language, 'admin' => $this->admin));
    }