protected function handleLoginRetreat(Request $request, RedirectResponse $response)
    {
        $route = $request->attributes->get('_route');

        if ($response->getTargetUrl() === $this->urlGenerator->generate('login') && $route !== 'logout') {
            $this->session->set(
                'retreat',
                [
                    'route'  => $route,
                    'params' => $request->attributes->get('_route_params'),
                ]
            );
        } else {
            $this->session->remove('retreat');
        }
    }
protected function handleLoginRetreat(Request $request, RedirectResponse $response)
    {
        $route = $request->attributes->get('_route');

        if ($response->getTargetUrl() === $this->urlGenerator->generate('login') && $route !== 'logout') {
            $this->session->set(
                'retreat',
                [
                    'route'  => $route,
                    'params' => $request->attributes->get('_route_params'),
                ]
            );
        } else {
            $this->session->remove('retreat');
        }
    }
protected function handleLoginRetreat ( Request $ request , RedirectResponse $ response ) { $ route = $ request -> attributes -> get ( '_route' ) ; if ( $ response -> getTargetUrl ( ) === $ this -> urlGenerator -> generate ( 'login' ) && $ route !== 'logout' ) { $ this -> session -> set ( 'retreat' , [ 'route' => $ route , 'params' => $ request -> attributes -> get ( '_route_params' ) , ] ) ; } else { $ this -> session -> remove ( 'retreat' ) ; } }
When redirecting to login page set the 'retreat' variable in the session.
This allows a redirect back to the current page after successful login.

@param \Symfony\Component\HttpFoundation\Request          $request
@param \Symfony\Component\HttpFoundation\RedirectResponse $response
When redirecting to login page set the retreat variable in the session . This allows a redirect back to the current page after successful login .