function Cookie::addCheckToUrl

Same name in other branches
  1. 9 core/modules/user/src/Authentication/Provider/Cookie.php \Drupal\user\Authentication\Provider\Cookie::addCheckToUrl()
  2. 11.x core/modules/user/src/Authentication/Provider/Cookie.php \Drupal\user\Authentication\Provider\Cookie::addCheckToUrl()

Adds a query parameter to check successful log in redirect URL.

Parameters

\Symfony\Component\HttpKernel\Event\ResponseEvent $event: The Event to process.

File

core/modules/user/src/Authentication/Provider/Cookie.php, line 124

Class

Cookie
Cookie based authentication provider.

Namespace

Drupal\user\Authentication\Provider

Code

public function addCheckToUrl(ResponseEvent $event) {
    $response = $event->getResponse();
    if ($response instanceof RedirectResponse) {
        if ($event->getRequest()
            ->getSession()
            ->has('check_logged_in')) {
            $event->getRequest()
                ->getSession()
                ->remove('check_logged_in');
            $url = $response->getTargetUrl();
            $options = UrlHelper::parse($url);
            $options['query']['check_logged_in'] = '1';
            $url = $options['path'] . '?' . UrlHelper::buildQuery($options['query']);
            if (!empty($options['fragment'])) {
                $url .= '#' . $options['fragment'];
            }
            // In the case of trusted redirect, we have to update the list of
            // trusted URLs because here we've just modified its target URL
            // which is in the list.
            if ($response instanceof TrustedRedirectResponse) {
                $response->setTrustedTargetUrl($url);
            }
            $response->setTargetUrl($url);
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.