0

I try to set up a simple CMS on our web application using the Symfony CMF. I can successfully load the fixtures in multiple languages.

$parent = $dm->find(null, '/cms/pages');
$rootPage = new Page(array('add_locale_pattern' => true));
$rootPage->setTitle('main');
$rootPage->setParentDocument($parent);
$rootPage->setName('main');
$rootPage->setBody('');
$dm->persist($rootPage);

$aboutPage = new Page(array('add_locale_pattern' => true));
$aboutPage->setTitle('About');
$aboutPage->setParentDocument($rootPage);
$aboutPage->setBody('About us DE');
$aboutPage->setName('about');
$aboutPage->setLabel('About');
$dm->persist($aboutPage);
$dm->bindTranslation($aboutPage, 'de');
$aboutPage->setBody('About us FR');
$aboutPage->setLabel('About FR');
$dm->bindTranslation($aboutPage, 'fr');

I can also display them in the right language (current locale) on the front page.

This is my controller action:

public function pageAction(Request $request, $contentDocument) {
    return $this->render(':Frontend/CMS:index.html.twig', ['page' => $contentDocument]);
}

And this is my working twig File:

{{ page.body }}

Screenshot of the working page

But as soon as I try to render a menu on my page, it will show the text in the default language.

{{ knp_menu_render('main') }}
{{ page.body }}

Screenshot of the non working page

The menu is configured as follow:

cmf_menu:
    persistence:
        phpcr:
            menu_basepath: /cms/pages

The output of app.request.locale is always fr. No matter if I include the menu or not.

Does anyone have an idea what could cause this problem?

  • this seems strange. are you sure you request the non-working page in a way that symfony sets the locale to fr? can you output app.request.locale in twig to check if there is a problem on that level? – dbu Aug 31 '16 at 10:00
  • Thank you for your answer. I just edited my post. Locale is always **fr**. – Ramon Rainer Aug 31 '16 at 13:38
  • do you output the locale before or after outputting the menu? as this is the only change, it smells like rendering the menu could trigger the locale to change. and maybe this helps: there is usually something that determines the locale based on the request (core symfony, its the _locale in the route definition, with the cmf we usually use LuneticLocaleBundle) and then there is a request listener from the phpcr-odm bundle to set the language fallback order based on the request locale. if that all works correctly, it feels like something resets the locale – dbu Sep 05 '16 at 07:25

0 Answers0