From a073064900b36c5016edc252e0d3a6c831154caf Mon Sep 17 00:00:00 2001 From: Kevin Papst Date: Thu, 15 Nov 2018 12:06:57 +0100 Subject: [PATCH] redirect to user language after profile update (#421) --- src/Controller/ProfileController.php | 8 +++++++- tests/Controller/ProfileControllerTest.php | 4 +++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Controller/ProfileController.php b/src/Controller/ProfileController.php index be4dea2f..44e5cf9d 100644 --- a/src/Controller/ProfileController.php +++ b/src/Controller/ProfileController.php @@ -194,7 +194,13 @@ class ProfileController extends AbstractController $this->flashSuccess('action.update.success'); - return $this->redirectToRoute('user_profile_preferences', ['username' => $profile->getUsername()]); + // switch locale if neccessary + $locale = $profile->getPreferenceValue('language', $request->getLocale()); + + return $this->redirectToRoute('user_profile_preferences', [ + '_locale' => $locale, + 'username' => $profile->getUsername() + ]); } return $this->getProfileView($profile, 'preferences', null, null, null, $form); diff --git a/tests/Controller/ProfileControllerTest.php b/tests/Controller/ProfileControllerTest.php index 9a2d9036..33ebb0eb 100644 --- a/tests/Controller/ProfileControllerTest.php +++ b/tests/Controller/ProfileControllerTest.php @@ -242,7 +242,9 @@ class ProfileControllerTest extends ControllerBaseTest ] ]); - $this->assertIsRedirect($client, $this->createUrl('/profile/' . urlencode(UserFixtures::USERNAME_USER) . '/prefs')); + $targetUrl = '/ar/profile/' . urlencode(UserFixtures::USERNAME_USER) . '/prefs'; + + $this->assertIsRedirect($client, $targetUrl); $client->followRedirect(); $this->assertTrue($client->getResponse()->isSuccessful());