Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 580b249

Browse files
committed
merged branch uwej711/fix_locale_is_overridden_2_1 (PR #7686)
This PR was merged into the 2.1 branch. Discussion ---------- [HttpKernel] fix overwriting of request's locale if attribute _locale is missing In addition to #7516 same change for the 2.1 branch, see comments on lunetics-org/LocaleBundle#59 Commits ------- da156d3 fix overwriting of request's locale if attribute _locale is missing
2 parents 41fef93 + da156d3 commit 580b249

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/Symfony/Component/HttpKernel/EventListener/LocaleListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function onKernelRequest(GetResponseEvent $event)
5050
$request = $event->getRequest();
5151

5252
$request->setDefaultLocale($this->defaultLocale);
53-
$this->setLocale($request, $request->attributes->get('_locale', $this->defaultLocale));
53+
$this->setLocale($request, $request->attributes->get('_locale', $request->getLocale()));
5454

5555
array_unshift($this->locales, $request->getLocale());
5656
}

src/Symfony/Component/HttpKernel/Tests/EventListener/LocaleListenerTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,17 @@ public function testLocaleSetForRoutingContext()
6868
$listener->onKernelRequest($this->getEvent($request));
6969
}
7070

71+
public function testRequestLocaleIsNotOverridden()
72+
{
73+
$request = Request::create('/');
74+
$request->setLocale('de');
75+
$listener = new LocaleListener('fr');
76+
$event = $this->getEvent($request);
77+
78+
$listener->onKernelRequest($event);
79+
$this->assertEquals('de', $request->getLocale());
80+
}
81+
7182
private function getEvent(Request $request)
7283
{
7384
return new GetResponseEvent($this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'), $request, HttpKernelInterface::MASTER_REQUEST);

0 commit comments

Comments
 (0)