LocaleBundle icon indicating copy to clipboard operation
LocaleBundle copied to clipboard

Locale switch and forwards

Open thanosp opened this issue 12 years ago • 6 comments

If a forward happens in symfony (2.3 but i think 2.1 as well) the _route request attribute becomes empty. That means in some cases (when useController is off which is the default and on does not seem to work right now anyway) after a forward, TargetInformationBuilder will catch a RouteNotFoundException and the locales array for the locale switcher will be empty.

I think the bundle should be able to at least generate a fallback url in this case. Maybe use the redirect_to_route config option which in this case seems to be unused?

Or do you suggest anything else to try out?

thanosp avatar Aug 12 '13 15:08 thanosp

I can confirm this. I use the FrameworkBundle:TemplateController

{{ render(controller('FrameworkBundle:Template:template', {template: '::partials/top-bar.html.twig', maxAge: 3600, sharedAge: 3600}) }}

I just want to point out, that this will probably be an bigger issue, when ESI comes into play. The only solution, that comes into my mind, is to provide an own controller-action, that accepts all required parameters (optionally) and renders the template.

{{ render(controller('LuneticsLocaleBundle:Locale:renderer', {route: app.request.attributes.get('_route')})) }}

kingcrunch avatar Sep 06 '13 20:09 kingcrunch

Any idea how to best fix this?

lunetics avatar Sep 06 '13 20:09 lunetics

@lunetics Uh, too fast. I updated my comment. Doesn't mean, that this is the best, or only solution, but feels like the simplest for now. Up for discussion.

kingcrunch avatar Sep 06 '13 20:09 kingcrunch

@KingCrunch there was a point where i intentionally removed the locale from the request attributes, let me look in the older issues :)

lunetics avatar Sep 06 '13 21:09 lunetics

Any news an this issue? I can also confirm this using SF 2.3. A regular show action works as expected, only if I forward an action to another method the locales-array remains empty. It is set, I can even ladybug-dump the locales-array, it shows an empty array.

Config:

lunetics_locale:
    switcher:
        show_current_locale: true
    allowed_locales:
        - de
        - en
        - it
        - fr
    guessing_order:
        - query
        - router
        - session
        - cookie
    cookie:
        set_on_change: true

So while

return $this->redirect($this->generateUrl('certificate.show', ['id' => $certificate->getId()]));

works as it sould (it displays all four languages), the following action leaves the selector empty:

return $this->forward('WebBundle:EntryCertificate:finalized', ['id' => $certificate->getId()]);

Both of them share the same base.html which calls the locale_switcher:

{{ locale_switcher(null, null, 'WebBundle::localeSwitcherDropdown.html.twig') }}

fschaeffer avatar Jan 23 '14 09:01 fschaeffer

Still a problem in 2.5

nurikabe avatar Nov 17 '14 19:11 nurikabe