You are here

class RedirectAfterLogoutSubscriber in Redirect after logout 8

RedirectAfterLogoutSubscriber event subscriber.

@package Drupal\redirect_after_logout\EventSubscriber

Hierarchy

  • class \Drupal\redirect_after_logout\EventSubscriber\RedirectAfterLogoutSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of RedirectAfterLogoutSubscriber

1 string reference to 'RedirectAfterLogoutSubscriber'
redirect_after_logout.services.yml in ./redirect_after_logout.services.yml
redirect_after_logout.services.yml
1 service uses RedirectAfterLogoutSubscriber
redirect_after_logout_subscriber in ./redirect_after_logout.services.yml
\Drupal\redirect_after_logout\EventSubscriber\RedirectAfterLogoutSubscriber

File

src/EventSubscriber/RedirectAfterLogoutSubscriber.php, line 19

Namespace

Drupal\redirect_after_logout\EventSubscriber
View source
class RedirectAfterLogoutSubscriber implements EventSubscriberInterface {

  /**
   * The config factory.
   *
   * @var \Drupal\Core\Config\ConfigFactory
   */
  protected $configFactory;

  /**
   * {@inheritdoc}
   */
  public function __construct(ConfigFactory $configFactory) {
    $this->configFactory = $configFactory;
  }

  /**
   * Check redirection.
   *
   * @param \Symfony\Component\HttpKernel\Event\ResponseEvent $event
   *   Event.
   */
  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();
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events[KernelEvents::RESPONSE][] = [
      'checkRedirection',
    ];
    return $events;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RedirectAfterLogoutSubscriber::$configFactory protected property The config factory.
RedirectAfterLogoutSubscriber::checkRedirection public function Check redirection.
RedirectAfterLogoutSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
RedirectAfterLogoutSubscriber::__construct public function