{"action":"created","comment":{"url":"https://api.github.com/repos/symfony/symfony-docs/pulls/comments/23127074","id":23127074,"diff_hunk":"@@ -106,3 +106,86 @@ method::\n     {\n         $locale = $request->getLocale();\n     }\n+\n+Setting the locale based on the user entity\n+-------------------------------------------\n+\n+You might want to improve even further and want to define the locale based on\n+the user entity of the logged in user. However since the `LocaleListener` is called\n+before the `FirewallListener`, which is responsible for handling authentication and\n+is setting the user token into the `TokenStorage`, you have no access to the user\n+which is logged in.\n+\n+First lets pretend you have defined a property locale in your User Entity which you\n+want to be used as the locale for the given user. In order to achieve the wanted locale\n+configuration you can set the locale which is defined for the user to the session right\n+after the login. Fortunately you can hook into the login process and update your session\n+variable before the redirect to the first page. For this you need an event listener for the\n+`security.interactive_login` event.\n+\n+    // src/AppBundle/EventListener/UserLocaleListener.php\n+    namespace AppBundle\\EventListener;\n+\n+    use Symfony\\Component\\HttpFoundation\\Session\\Session;\n+    use Symfony\\Component\\Security\\Http\\Event\\InteractiveLoginEvent;\n+\n+    /**\n+     * Stores the locale of the user in the session after the\n+     * login. This can be used by the LocaleListener afterwards.\n+     */\n+    class UserLocaleListener\n+    {\n+        /**\n+         * @var Session\n+         */\n+        private $session;\n+        public function __construct(Session $session)\n+        {\n+            $this->session = $session;\n+        }\n+        /**\n+         * @param InteractiveLoginEvent $event\n+         */\n+        public function onInteractiveLogin(InteractiveLoginEvent $event)\n+        {\n+            $user = $event->getAuthenticationToken()->getUser();\n+            $this->session->set('_locale', $user->getLocale());\n+        }\n+    }\n+\n+Then register the listener:\n+\n+.. configuration-block::\n+\n+    .. code-block:: yaml\n+\n+        # app/config/services.yml\n+        services:\n+            app.user_locale_listener:\n+                class: AppBundle\\EventListener\\UserLocaleListener\n+                tags:\n+                    - { name: kernel.event_listener, event: security.interactive_login, method: onInteractiveLogin }\n+\n+    .. code-block:: xml\n+\n+        <!-- app/config/services.xml -->\n+        <service id=\"kernel.listener.your_listener_name\" class=\"AppBundle\\EventListener\\UserLocaleListener\">\n+            <tag name=\"kernel.event_listener\" event=\"security.interactive_login\" method=\"onInteractiveLogin\" />\n+        </service>\n+\n+    .. code-block:: php\n+\n+        // app/config/services.php\n+        $container\n+            ->register('kernel.listener.your_listener_name', 'AppBundle\\EventListener\\UserLocaleListener')\n+            ->addTag('kernel.event_listener', array('event' => 'security.interactive_login', 'method' => 'onInteractiveLogin'))\n+        ;\n+\n+.. caution::\n+\n+With this configuration you are all set for having the locale based on the user's","path":"cookbook/session/locale_sticky_session.rst","position":81,"original_position":81,"commit_id":"66e21a95bbd066cf1e0c011f1ed2b7271ccdb1bd","original_commit_id":"66e21a95bbd066cf1e0c011f1ed2b7271ccdb1bd","user":{"login":"javiereguiluz","id":73419,"avatar_url":"https://avatars.githubusercontent.com/u/73419?v=3","gravatar_id":"","url":"https://api.github.com/users/javiereguiluz","html_url":"https://github.com/javiereguiluz","followers_url":"https://api.github.com/users/javiereguiluz/followers","following_url":"https://api.github.com/users/javiereguiluz/following{/other_user}","gists_url":"https://api.github.com/users/javiereguiluz/gists{/gist_id}","starred_url":"https://api.github.com/users/javiereguiluz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/javiereguiluz/subscriptions","organizations_url":"https://api.github.com/users/javiereguiluz/orgs","repos_url":"https://api.github.com/users/javiereguiluz/repos","events_url":"https://api.github.com/users/javiereguiluz/events{/privacy}","received_events_url":"https://api.github.com/users/javiereguiluz/received_events","type":"User","site_admin":false},"body":"The contents of the `caution` admonition need to be indented by 4 spaces.","created_at":"2015-01-17T18:01:33Z","updated_at":"2015-01-17T18:01:33Z","html_url":"https://github.com/symfony/symfony-docs/pull/4875#discussion_r23127074","pull_request_url":"https://api.github.com/repos/symfony/symfony-docs/pulls/4875","_links":{"self":{"href":"https://api.github.com/repos/symfony/symfony-docs/pulls/comments/23127074"},"html":{"href":"https://github.com/symfony/symfony-docs/pull/4875#discussion_r23127074"},"pull_request":{"href":"https://api.github.com/repos/symfony/symfony-docs/pulls/4875"}}},"pull_request":{"url":"https://api.github.com/repos/symfony/symfony-docs/pulls/4875","id":27559692,"html_url":"https://github.com/symfony/symfony-docs/pull/4875","diff_url":"https://github.com/symfony/symfony-docs/pull/4875.diff","patch_url":"https://github.com/symfony/symfony-docs/pull/4875.patch","issue_url":"https://api.github.com/repos/symfony/symfony-docs/issues/4875","number":4875,"state":"open","locked":false,"title":"Added chapter about the locale based on the user entity","user":{"login":"peterrehm","id":2010989,"avatar_url":"https://avatars.githubusercontent.com/u/2010989?v=3","gravatar_id":"","url":"https://api.github.com/users/peterrehm","html_url":"https://github.com/peterrehm","followers_url":"https://api.github.com/users/peterrehm/followers","following_url":"https://api.github.com/users/peterrehm/following{/other_user}","gists_url":"https://api.github.com/users/peterrehm/gists{/gist_id}","starred_url":"https://api.github.com/users/peterrehm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peterrehm/subscriptions","organizations_url":"https://api.github.com/users/peterrehm/orgs","repos_url":"https://api.github.com/users/peterrehm/repos","events_url":"https://api.github.com/users/peterrehm/events{/privacy}","received_events_url":"https://api.github.com/users/peterrehm/received_events","type":"User","site_admin":false},"body":"| Q             | A\r\n| ------------- | ---\r\n| Doc fix?      | no\r\n| New docs?     | yes\r\n| Applies to    | 2.3\r\n| Fixed tickets | #4862","created_at":"2015-01-17T17:52:25Z","updated_at":"2015-01-17T18:01:33Z","closed_at":null,"merged_at":null,"merge_commit_sha":"be97a0be9c02f1e06ab564d3a910d7cd1e2bc683","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/symfony/symfony-docs/pulls/4875/commits","review_comments_url":"https://api.github.com/repos/symfony/symfony-docs/pulls/4875/comments","review_comment_url":"https://api.github.com/repos/symfony/symfony-docs/pulls/comments/{number}","comments_url":"https://api.github.com/repos/symfony/symfony-docs/issues/4875/comments","statuses_url":"https://api.github.com/repos/symfony/symfony-docs/statuses/66e21a95bbd066cf1e0c011f1ed2b7271ccdb1bd","head":{"label":"peterrehm:locale-user-dependend","ref":"locale-user-dependend","sha":"66e21a95bbd066cf1e0c011f1ed2b7271ccdb1bd","user":{"login":"peterrehm","id":2010989,"avatar_url":"https://avatars.githubusercontent.com/u/2010989?v=3","gravatar_id":"","url":"https://api.github.com/users/peterrehm","html_url":"https://github.com/peterrehm","followers_url":"https://api.github.com/users/peterrehm/followers","following_url":"https://api.github.com/users/peterrehm/following{/other_user}","gists_url":"https://api.github.com/users/peterrehm/gists{/gist_id}","starred_url":"https://api.github.com/users/peterrehm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peterrehm/subscriptions","organizations_url":"https://api.github.com/users/peterrehm/orgs","repos_url":"https://api.github.com/users/peterrehm/repos","events_url":"https://api.github.com/users/peterrehm/events{/privacy}","received_events_url":"https://api.github.com/users/peterrehm/received_events","type":"User","site_admin":false},"repo":{"id":6839088,"name":"symfony-docs","full_name":"peterrehm/symfony-docs","owner":{"login":"peterrehm","id":2010989,"avatar_url":"https://avatars.githubusercontent.com/u/2010989?v=3","gravatar_id":"","url":"https://api.github.com/users/peterrehm","html_url":"https://github.com/peterrehm","followers_url":"https://api.github.com/users/peterrehm/followers","following_url":"https://api.github.com/users/peterrehm/following{/other_user}","gists_url":"https://api.github.com/users/peterrehm/gists{/gist_id}","starred_url":"https://api.github.com/users/peterrehm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peterrehm/subscriptions","organizations_url":"https://api.github.com/users/peterrehm/orgs","repos_url":"https://api.github.com/users/peterrehm/repos","events_url":"https://api.github.com/users/peterrehm/events{/privacy}","received_events_url":"https://api.github.com/users/peterrehm/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/peterrehm/symfony-docs","description":"The Symfony2 documentation","fork":true,"url":"https://api.github.com/repos/peterrehm/symfony-docs","forks_url":"https://api.github.com/repos/peterrehm/symfony-docs/forks","keys_url":"https://api.github.com/repos/peterrehm/symfony-docs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/peterrehm/symfony-docs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/peterrehm/symfony-docs/teams","hooks_url":"https://api.github.com/repos/peterrehm/symfony-docs/hooks","issue_events_url":"https://api.github.com/repos/peterrehm/symfony-docs/issues/events{/number}","events_url":"https://api.github.com/repos/peterrehm/symfony-docs/events","assignees_url":"https://api.github.com/repos/peterrehm/symfony-docs/assignees{/user}","branches_url":"https://api.github.com/repos/peterrehm/symfony-docs/branches{/branch}","tags_url":"https://api.github.com/repos/peterrehm/symfony-docs/tags","blobs_url":"https://api.github.com/repos/peterrehm/symfony-docs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/peterrehm/symfony-docs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/peterrehm/symfony-docs/git/refs{/sha}","trees_url":"https://api.github.com/repos/peterrehm/symfony-docs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/peterrehm/symfony-docs/statuses/{sha}","languages_url":"https://api.github.com/repos/peterrehm/symfony-docs/languages","stargazers_url":"https://api.github.com/repos/peterrehm/symfony-docs/stargazers","contributors_url":"https://api.github.com/repos/peterrehm/symfony-docs/contributors","subscribers_url":"https://api.github.com/repos/peterrehm/symfony-docs/subscribers","subscription_url":"https://api.github.com/repos/peterrehm/symfony-docs/subscription","commits_url":"https://api.github.com/repos/peterrehm/symfony-docs/commits{/sha}","git_commits_url":"https://api.github.com/repos/peterrehm/symfony-docs/git/commits{/sha}","comments_url":"https://api.github.com/repos/peterrehm/symfony-docs/comments{/number}","issue_comment_url":"https://api.github.com/repos/peterrehm/symfony-docs/issues/comments/{number}","contents_url":"https://api.github.com/repos/peterrehm/symfony-docs/contents/{+path}","compare_url":"https://api.github.com/repos/peterrehm/symfony-docs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/peterrehm/symfony-docs/merges","archive_url":"https://api.github.com/repos/peterrehm/symfony-docs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/peterrehm/symfony-docs/downloads","issues_url":"https://api.github.com/repos/peterrehm/symfony-docs/issues{/number}","pulls_url":"https://api.github.com/repos/peterrehm/symfony-docs/pulls{/number}","milestones_url":"https://api.github.com/repos/peterrehm/symfony-docs/milestones{/number}","notifications_url":"https://api.github.com/repos/peterrehm/symfony-docs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/peterrehm/symfony-docs/labels{/name}","releases_url":"https://api.github.com/repos/peterrehm/symfony-docs/releases{/id}","created_at":"2012-11-24T11:40:01Z","updated_at":"2014-08-21T19:15:07Z","pushed_at":"2015-01-17T17:51:27Z","git_url":"git://github.com/peterrehm/symfony-docs.git","ssh_url":"git@github.com:peterrehm/symfony-docs.git","clone_url":"https://github.com/peterrehm/symfony-docs.git","svn_url":"https://github.com/peterrehm/symfony-docs","homepage":"http://symfony.com/doc/current/","size":24746,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"symfony:2.3","ref":"2.3","sha":"9fee9eed5366a1a4408821cfc950a34ea4c7fbce","user":{"login":"symfony","id":143937,"avatar_url":"https://avatars.githubusercontent.com/u/143937?v=3","gravatar_id":"","url":"https://api.github.com/users/symfony","html_url":"https://github.com/symfony","followers_url":"https://api.github.com/users/symfony/followers","following_url":"https://api.github.com/users/symfony/following{/other_user}","gists_url":"https://api.github.com/users/symfony/gists{/gist_id}","starred_url":"https://api.github.com/users/symfony/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/symfony/subscriptions","organizations_url":"https://api.github.com/users/symfony/orgs","repos_url":"https://api.github.com/users/symfony/repos","events_url":"https://api.github.com/users/symfony/events{/privacy}","received_events_url":"https://api.github.com/users/symfony/received_events","type":"Organization","site_admin":false},"repo":{"id":521583,"name":"symfony-docs","full_name":"symfony/symfony-docs","owner":{"login":"symfony","id":143937,"avatar_url":"https://avatars.githubusercontent.com/u/143937?v=3","gravatar_id":"","url":"https://api.github.com/users/symfony","html_url":"https://github.com/symfony","followers_url":"https://api.github.com/users/symfony/followers","following_url":"https://api.github.com/users/symfony/following{/other_user}","gists_url":"https://api.github.com/users/symfony/gists{/gist_id}","starred_url":"https://api.github.com/users/symfony/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/symfony/subscriptions","organizations_url":"https://api.github.com/users/symfony/orgs","repos_url":"https://api.github.com/users/symfony/repos","events_url":"https://api.github.com/users/symfony/events{/privacy}","received_events_url":"https://api.github.com/users/symfony/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/symfony/symfony-docs","description":"The Symfony2 documentation","fork":false,"url":"https://api.github.com/repos/symfony/symfony-docs","forks_url":"https://api.github.com/repos/symfony/symfony-docs/forks","keys_url":"https://api.github.com/repos/symfony/symfony-docs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/symfony/symfony-docs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/symfony/symfony-docs/teams","hooks_url":"https://api.github.com/repos/symfony/symfony-docs/hooks","issue_events_url":"https://api.github.com/repos/symfony/symfony-docs/issues/events{/number}","events_url":"https://api.github.com/repos/symfony/symfony-docs/events","assignees_url":"https://api.github.com/repos/symfony/symfony-docs/assignees{/user}","branches_url":"https://api.github.com/repos/symfony/symfony-docs/branches{/branch}","tags_url":"https://api.github.com/repos/symfony/symfony-docs/tags","blobs_url":"https://api.github.com/repos/symfony/symfony-docs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/symfony/symfony-docs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/symfony/symfony-docs/git/refs{/sha}","trees_url":"https://api.github.com/repos/symfony/symfony-docs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/symfony/symfony-docs/statuses/{sha}","languages_url":"https://api.github.com/repos/symfony/symfony-docs/languages","stargazers_url":"https://api.github.com/repos/symfony/symfony-docs/stargazers","contributors_url":"https://api.github.com/repos/symfony/symfony-docs/contributors","subscribers_url":"https://api.github.com/repos/symfony/symfony-docs/subscribers","subscription_url":"https://api.github.com/repos/symfony/symfony-docs/subscription","commits_url":"https://api.github.com/repos/symfony/symfony-docs/commits{/sha}","git_commits_url":"https://api.github.com/repos/symfony/symfony-docs/git/commits{/sha}","comments_url":"https://api.github.com/repos/symfony/symfony-docs/comments{/number}","issue_comment_url":"https://api.github.com/repos/symfony/symfony-docs/issues/comments/{number}","contents_url":"https://api.github.com/repos/symfony/symfony-docs/contents/{+path}","compare_url":"https://api.github.com/repos/symfony/symfony-docs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/symfony/symfony-docs/merges","archive_url":"https://api.github.com/repos/symfony/symfony-docs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/symfony/symfony-docs/downloads","issues_url":"https://api.github.com/repos/symfony/symfony-docs/issues{/number}","pulls_url":"https://api.github.com/repos/symfony/symfony-docs/pulls{/number}","milestones_url":"https://api.github.com/repos/symfony/symfony-docs/milestones{/number}","notifications_url":"https://api.github.com/repos/symfony/symfony-docs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/symfony/symfony-docs/labels{/name}","releases_url":"https://api.github.com/repos/symfony/symfony-docs/releases{/id}","created_at":"2010-02-17T08:43:51Z","updated_at":"2015-01-16T19:36:29Z","pushed_at":"2015-01-17T09:35:33Z","git_url":"git://github.com/symfony/symfony-docs.git","ssh_url":"git@github.com:symfony/symfony-docs.git","clone_url":"https://github.com/symfony/symfony-docs.git","svn_url":"https://github.com/symfony/symfony-docs","homepage":"http://symfony.com/doc/current/","size":53140,"stargazers_count":945,"watchers_count":945,"language":"Python","has_issues":true,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":1653,"mirror_url":null,"open_issues_count":269,"forks":1653,"open_issues":269,"watchers":945,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/symfony/symfony-docs/pulls/4875"},"html":{"href":"https://github.com/symfony/symfony-docs/pull/4875"},"issue":{"href":"https://api.github.com/repos/symfony/symfony-docs/issues/4875"},"comments":{"href":"https://api.github.com/repos/symfony/symfony-docs/issues/4875/comments"},"review_comments":{"href":"https://api.github.com/repos/symfony/symfony-docs/pulls/4875/comments"},"review_comment":{"href":"https://api.github.com/repos/symfony/symfony-docs/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/symfony/symfony-docs/pulls/4875/commits"},"statuses":{"href":"https://api.github.com/repos/symfony/symfony-docs/statuses/66e21a95bbd066cf1e0c011f1ed2b7271ccdb1bd"}}}}