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'
1 service uses RedirectAfterLogoutSubscriber
File
- src/
EventSubscriber/ RedirectAfterLogoutSubscriber.php, line 19
Namespace
Drupal\redirect_after_logout\EventSubscriberView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RedirectAfterLogoutSubscriber:: |
protected | property | The config factory. | |
RedirectAfterLogoutSubscriber:: |
public | function | Check redirection. | |
RedirectAfterLogoutSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
RedirectAfterLogoutSubscriber:: |
public | function |