protected function WebformExceptionHtmlSubscriber::redirectToLogin in Webform 8.5
Same name and namespace in other branches
- 6.x src/EventSubscriber/WebformExceptionHtmlSubscriber.php \Drupal\webform\EventSubscriber\WebformExceptionHtmlSubscriber::redirectToLogin()
Redirect to user login with destination and display custom message.
Parameters
\Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event: The event to process.
null|string $message: (Optional) Message to be display on user login.
null|\Drupal\Core\Entity\EntityInterface $entity: (Optional) Entity to be used when replacing tokens.
2 calls to WebformExceptionHtmlSubscriber::redirectToLogin()
- WebformExceptionHtmlSubscriber::on403RedirectEntityAccess in src/
EventSubscriber/ WebformExceptionHtmlSubscriber.php - Redirect to user login when access is denied for webform or submission.
- WebformExceptionHtmlSubscriber::on403RedirectPrivateFileAccess in src/
EventSubscriber/ WebformExceptionHtmlSubscriber.php - Redirect to user login when access is denied to private webform file.
File
- src/
EventSubscriber/ WebformExceptionHtmlSubscriber.php, line 292
Class
- WebformExceptionHtmlSubscriber
- Event subscriber to redirect to login form when webform settings instruct to.
Namespace
Drupal\webform\EventSubscriberCode
protected function redirectToLogin(GetResponseForExceptionEvent $event, $message = NULL, EntityInterface $entity = NULL) {
// Display message.
if ($message) {
$this
->setMessage($message, $entity);
}
// Only redirect anonymous users.
if ($this->account
->isAuthenticated()) {
return;
}
$redirect_url = Url::fromRoute('user.login', [], [
'absolute' => TRUE,
'query' => $this->redirectDestination
->getAsArray(),
]);
$event
->setResponse(new RedirectResponse($redirect_url
->toString()));
}