You are here

public function RedirectAfterLogoutSubscriber::checkRedirection in Redirect after logout 8

Check redirection.

Parameters

\Symfony\Component\HttpKernel\Event\ResponseEvent $event: Event.

File

src/EventSubscriber/RedirectAfterLogoutSubscriber.php, line 41

Class

RedirectAfterLogoutSubscriber
RedirectAfterLogoutSubscriber event subscriber.

Namespace

Drupal\redirect_after_logout\EventSubscriber

Code

public function checkRedirection(FilterResponseEvent $event) {
  $destination =& drupal_static('redirect_after_logout_user_logout');
  $response = $event
    ->getResponse();
  if (!$response instanceof RedirectResponse || !$destination) {
    return;
  }
  if ($destination == '<front>') {
    $destination = Url::fromRoute($destination);
  }
  elseif (UrlHelper::isExternal($destination)) {
    $destination = Url::fromUri($destination);
  }
  else {
    $destination = Url::fromUri('internal:' . $destination);
  }
  $config = $this->configFactory
    ->get('redirect_after_logout.settings');
  $logout_message = $config
    ->get('message');
  if (empty($logout_message) || $destination
    ->isExternal()) {
    $destination = $destination
      ->toString();
  }
  else {
    $destination = $destination
      ->setOption('query', [
      'logout-message' => 1,
    ])
      ->toString();
  }
  $response = new RedirectResponse($destination);
  $response
    ->send();
}