-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Twig path function fails for internationalized routes #30010
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
What do you mean exactly by |
Stack trace: https://pastebin.com/hbvFgUiu |
To be 100% clear: this template renders fine when it is rendered from a controller. The error just occurs when I do the rendering from the EventListener that reacts to 404. Presumably some initialization has not happened yet at that point, or maybe I am accessing the wrong twig instance or something like that. As mentioned, I looked though the Symfony source a bunch though it's hard to follow things due to magical dependency injection which I am not used to. |
I guess the problem is that the exception occurs before the |
Status: Reviewed Exactly xabbuh. Just reproduced it successfully.
However, there is a little fix we can do. We currently don't pass a default locale to the generator. We should pass the |
If you rely on the locale being extracted from the route configuration, I think we cannot do better as there is no matching route that could be used to extract the locale. When using something more sophisticated with custom code (e.g. storing the locale in the session), you could of course make sure that your own listener is executed before. |
I thought about my proposition a bit more and actually it would lead to BC breaks if there is another non internationalized route with the same name. Exemple : "myroute" and "myroute.en" |
I got around the linking via $this->urlGenerator->getContext()->setParameter(
'_locale',
$locale
); While that solves the linking issue, the template is rendered with the default locale, rather than the one I am computing from the url in my EventListener. I've switched to using some catch-all routes for 404 rather than using an EventListener. This approach is much simpler and works nicely with the new Symfony internationalized routing (unlike the JMS bundle where I did not get it to work for the life of me). So this bug is no longer getting in my way. Still, it seems like the route function / UrlGenerator should at least fall back to the default locale and not error out. |
Does #31023 help? |
I ran |
Your problem might be having yet another locale set. I've encourted similar issue here: Trying to workaround this. |
Symfony version(s) affected: 4.2.2
Description
The Twig path function fails for internationalized routes when rendering a template on
NotFoundHttpException
.How to reproduce
1/3: Have an internationalized route (
routes.yaml
):2/3: Have an EventListener that renders a 404 template:
3/3: Call the
path
function with the name of the internationalized route in the template:The path function works fine for routes that do not use the i18n feature like this one:
I did some digging though the Symfony code though did not find the issue. Might be related to #27872
The text was updated successfully, but these errors were encountered: