Skip to content

fix the event subscriber code example #10546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 25, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 6 additions & 42 deletions session/locale_sticky_session.rst
Original file line number Diff line number Diff line change
Expand Up @@ -169,50 +169,14 @@ event::
$this->session->set('_locale', $user->getLocale());
}
}
}

Then register the listener:

.. configuration-block::

.. code-block:: yaml

# config/services.yaml
services:
App\EventListener\UserLocaleListener:
tags:
- { name: kernel.event_listener, event: security.interactive_login, method: onInteractiveLogin, priority: 15 }

.. code-block:: xml

<!-- config/services.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services
http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="App\EventListener\UserLocaleListener">
<tag name="kernel.event_listener"
event="security.interactive_login"
method="onInteractiveLogin" priority=15 />
</service>
</services>
</container>

.. code-block:: php

// config/services.php
use AppBundle\EventListener\UserLocaleListener;
use Symfony\Component\DependencyInjection\Reference;

$container
->register(UserLocaleListener::class)
->addTag(
'kernel.event_listener',
array('event' => 'security.interactive_login', 'method' => 'onInteractiveLogin', 'priority' => 15)
public static function getSubscribedEvents()
{
return array(
SecurityEvents::INTERACTIVE_LOGIN => 'onInteractiveLogin',
);
}
}

.. caution::

Expand Down