[FrameworkBundle] added the current locale as the default value for _locale when generating routes
This commit is contained in:
parent
c6dcf0f8f3
commit
7266b41ade
@ -77,14 +77,20 @@ class RequestListener
|
|||||||
if ($master) {
|
if ($master) {
|
||||||
// set the context even if the parsing does not need to be done
|
// set the context even if the parsing does not need to be done
|
||||||
// to have correct link generation
|
// to have correct link generation
|
||||||
$this->router->setContext(new RequestContext(
|
$context = new RequestContext(
|
||||||
$request->getBaseUrl(),
|
$request->getBaseUrl(),
|
||||||
$request->getMethod(),
|
$request->getMethod(),
|
||||||
$request->getHost(),
|
$request->getHost(),
|
||||||
$request->getScheme(),
|
$request->getScheme(),
|
||||||
$this->httpPort,
|
$this->httpPort,
|
||||||
$this->httpsPort
|
$this->httpsPort
|
||||||
));
|
);
|
||||||
|
|
||||||
|
if ($session = $request->getSession()) {
|
||||||
|
$context->setParameter('_locale', $session->getLocale());
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->router->setContext($context);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->attributes->has('_controller')) {
|
if ($request->attributes->has('_controller')) {
|
||||||
@ -101,10 +107,6 @@ class RequestListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
$request->attributes->add($parameters);
|
$request->attributes->add($parameters);
|
||||||
|
|
||||||
if ($locale = $request->attributes->get('_locale')) {
|
|
||||||
$request->getSession()->setLocale($locale);
|
|
||||||
}
|
|
||||||
} catch (NotFoundException $e) {
|
} catch (NotFoundException $e) {
|
||||||
$message = sprintf('No route found for "%s %s"', $request->getMethod(), $request->getPathInfo());
|
$message = sprintf('No route found for "%s %s"', $request->getMethod(), $request->getPathInfo());
|
||||||
if (null !== $this->logger) {
|
if (null !== $this->logger) {
|
||||||
@ -118,6 +120,11 @@ class RequestListener
|
|||||||
}
|
}
|
||||||
throw new MethodNotAllowedHttpException($e->getAllowedMethods(), $message, $e);
|
throw new MethodNotAllowedHttpException($e->getAllowedMethods(), $message, $e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($master && $locale = $request->attributes->get('_locale')) {
|
||||||
|
$request->getSession()->setLocale($locale);
|
||||||
|
$context->setParameter('_locale', $locale);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function parametersToString(array $parameters)
|
private function parametersToString(array $parameters)
|
||||||
|
Reference in New Issue
Block a user