File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -151,3 +151,50 @@ setting:
151
151
),
152
152
),
153
153
));
154
+
155
+ Events
156
+ ------
157
+
158
+ The firewall dispatches the ``security.switch_user `` event right after the impersonation
159
+ completed. The ``SwitchUserEvent `` is passed to the listener, based on which you are able
160
+ to get the target user you impersonate.
161
+
162
+ The cookbook article about :ref: `Making the Locale "Sticky" during a User's Session
163
+ <cookbook/session/locale_sticky_session>` does not take any changing locale into account.
164
+ The following code sample will show how to change the sticky locale:
165
+
166
+ .. configuration-block ::
167
+
168
+ .. code-block :: yaml
169
+
170
+ # app/config/services.yml
171
+ services :
172
+ app.switch_user_listener :
173
+ class : AppBundle\EventListener\SwitchUserListener
174
+ tags :
175
+ - { name: kernel.event_listener, event: security.switch_user, method: onSwitchUser }
176
+
177
+ .. caution ::
178
+
179
+ The listener implementation assumes your ``User `` entity has ``getLocale() ``.
180
+
181
+ .. code-block :: php
182
+
183
+ // src/AppBundle/EventListener/SwitchUserListener.pnp
184
+
185
+ use Symfony\Component\Security\Http\Event\SwitchUserEvent;
186
+
187
+ class SwitchUserListener
188
+ {
189
+ /**
190
+ * @param SwitchUserEvent $event
191
+ */
192
+ public function onSwitchUser(SwitchUserEvent $event)
193
+ {
194
+ $event->getRequest()->getSession()->set(
195
+ '_locale',
196
+ $event->getTargetUser()->getLocale()
197
+ );
198
+ }
199
+ }
200
+
You can’t perform that action at this time.
0 commit comments