Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FosUserBundle redirect in a FilterUserResponseEvent

I want to redirect my user after he clicks on the registration link but I'm stuck because there is no setResponse method in a FilterUserResponseEvent

RegistrationListenner.php

public static function getSubscribedEvents()
{
    return array(
        FOSUserEvents::REGISTRATION_CONFIRMED => 'onRegistrationConfirmed',
    );
}


public function onRegistrationConfirmed(FilterUserResponseEvent $event)
{
    $url = $this->router->generate('my_route', array('foo' => 'bar'));
    $response = new RedirectResponse($url);
    $event->setResponse(new RedirectResponse($url));
}

services.xml

    <service id="myapp.profile" class="MyApp\UserBundle\EventListener\ProfileListener">
        <tag name="kernel.event_subscriber"/>
        <argument type="service" id="router" />
    </service>
like image 524
Tib Avatar asked May 08 '26 04:05

Tib


1 Answers

For this purpose there is the GetResponseUserEvent at the REGISTRATION_CONFIRM event, which asks for a response:

public static function getSubscribedEvents()
{
    return array(
            FOSUserEvents::REGISTRATION_CONFIRM => 'onRegistrationConfirm',
    );
}

public function onRegistrationConfirm(GetResponseUserEvent $event)
{
    $url = $this->router->generate('my_route', array('foo' => 'bar'));
    $response = new RedirectResponse($url);
    $event->setResponse(new RedirectResponse($url));
}
like image 100
Emii Khaos Avatar answered May 09 '26 20:05

Emii Khaos