public function registerPreviousUrl(PostResponseEvent  $event)
    {
        $request = $event->getRequest();

        if (!$request->isXmlHttpRequest() && $event->getResponse()->isSuccessful()) {
            $referrer = $request->attributes->get('_previous_url', null);

            $catalogViews = ['category', 'product'];

            $view = $request->attributes->get('_view', null);

            if (null !== $referrer) {
                // A previous URL (or the keyword 'dont-save') has been specified.
                if ('dont-save' == $referrer) {
                    // We should not save the current URL as the previous URL
                    $referrer = null;
                }
            } else {
                // The current URL will become the previous URL
                $referrer = $request->getUri();
            }

            // Set previous URL, if defined
            if (null !== $referrer) {
                /** @var Session $session */
                $session = $request->getSession();

                if (ConfigQuery::isMultiDomainActivated()) {
                    $components = parse_url($referrer);
                    $lang = LangQuery::create()
                        ->filterByUrl(sprintf("%s://%s", $components["scheme"], $components["host"]), ModelCriteria::LIKE)
                        ->findOne();

                    if (null !== $lang) {
                        $session->setReturnToUrl($referrer);

                        if (\in_array($view, $catalogViews)) {
                            $session->setReturnToCatalogLastUrl($referrer);
                        }
                    }
                } else {
                    if (false !== strpos($referrer, $request->getSchemeAndHttpHost())) {
                        $session->setReturnToUrl($referrer);

                        if (\in_array($view, $catalogViews)) {
                            $session->setReturnToCatalogLastUrl($referrer);
                        }
                    }
                }
            }
        }
    }
public function registerPreviousUrl(PostResponseEvent  $event)
    {
        $request = $event->getRequest();

        if (!$request->isXmlHttpRequest() && $event->getResponse()->isSuccessful()) {
            $referrer = $request->attributes->get('_previous_url', null);

            $catalogViews = ['category', 'product'];

            $view = $request->attributes->get('_view', null);

            if (null !== $referrer) {
                // A previous URL (or the keyword 'dont-save') has been specified.
                if ('dont-save' == $referrer) {
                    // We should not save the current URL as the previous URL
                    $referrer = null;
                }
            } else {
                // The current URL will become the previous URL
                $referrer = $request->getUri();
            }

            // Set previous URL, if defined
            if (null !== $referrer) {
                /** @var Session $session */
                $session = $request->getSession();

                if (ConfigQuery::isMultiDomainActivated()) {
                    $components = parse_url($referrer);
                    $lang = LangQuery::create()
                        ->filterByUrl(sprintf("%s://%s", $components["scheme"], $components["host"]), ModelCriteria::LIKE)
                        ->findOne();

                    if (null !== $lang) {
                        $session->setReturnToUrl($referrer);

                        if (\in_array($view, $catalogViews)) {
                            $session->setReturnToCatalogLastUrl($referrer);
                        }
                    }
                } else {
                    if (false !== strpos($referrer, $request->getSchemeAndHttpHost())) {
                        $session->setReturnToUrl($referrer);

                        if (\in_array($view, $catalogViews)) {
                            $session->setReturnToCatalogLastUrl($referrer);
                        }
                    }
                }
            }
        }
    }
public function registerPreviousUrl ( PostResponseEvent $ event ) { $ request = $ event -> getRequest ( ) ; if ( ! $ request -> isXmlHttpRequest ( ) && $ event -> getResponse ( ) -> isSuccessful ( ) ) { $ referrer = $ request -> attributes -> get ( '_previous_url' , null ) ; $ catalogViews = [ 'category' , 'product' ] ; $ view = $ request -> attributes -> get ( '_view' , null ) ; if ( null !== $ referrer ) { // A previous URL (or the keyword 'dont-save') has been specified. if ( 'dont-save' == $ referrer ) { // We should not save the current URL as the previous URL $ referrer = null ; } } else { // The current URL will become the previous URL $ referrer = $ request -> getUri ( ) ; } // Set previous URL, if defined if ( null !== $ referrer ) { /** @var Session $session */ $ session = $ request -> getSession ( ) ; if ( ConfigQuery :: isMultiDomainActivated ( ) ) { $ components = parse_url ( $ referrer ) ; $ lang = LangQuery :: create ( ) -> filterByUrl ( sprintf ( "%s://%s" , $ components [ "scheme" ] , $ components [ "host" ] ) , ModelCriteria :: LIKE ) -> findOne ( ) ; if ( null !== $ lang ) { $ session -> setReturnToUrl ( $ referrer ) ; if ( \ in_array ( $ view , $ catalogViews ) ) { $ session -> setReturnToCatalogLastUrl ( $ referrer ) ; } } } else { if ( false !== strpos ( $ referrer , $ request -> getSchemeAndHttpHost ( ) ) ) { $ session -> setReturnToUrl ( $ referrer ) ; if ( \ in_array ( $ view , $ catalogViews ) ) { $ session -> setReturnToCatalogLastUrl ( $ referrer ) ; } } } } } }
Save the previous URL in session which is based on the referer header or the request, or
the _previous_url request attribute, if defined.

If the value of _previous_url is "dont-save", the current referrer is not saved.

@param \Symfony\Component\HttpKernel\Event\PostResponseEvent $event
Save the previous URL in session which is based on the referer header or the request or the _previous_url request attribute if defined .