You are here

protected function WebformDefaultExceptionHtmlSubscriber::redirectToLogin in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/EventSubscriber/WebformDefaultExceptionHtmlSubscriber.php \Drupal\webform\EventSubscriber\WebformDefaultExceptionHtmlSubscriber::redirectToLogin()

Redirect to user login with destination and display custom message.

Parameters

\Symfony\Component\HttpKernel\Event\ExceptionEvent $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 WebformDefaultExceptionHtmlSubscriber::redirectToLogin()
WebformDefaultExceptionHtmlSubscriber::on403RedirectEntityAccess in src/EventSubscriber/WebformDefaultExceptionHtmlSubscriber.php
Redirect to user login when access is denied for webform or submission.
WebformDefaultExceptionHtmlSubscriber::on403RedirectPrivateFileAccess in src/EventSubscriber/WebformDefaultExceptionHtmlSubscriber.php
Redirect to user login when access is denied to private webform file.

File

src/EventSubscriber/WebformDefaultExceptionHtmlSubscriber.php, line 292

Class

WebformDefaultExceptionHtmlSubscriber
Event subscriber to redirect to login form when webform settings instruct to.

Namespace

Drupal\webform\EventSubscriber

Code

protected function redirectToLogin(ExceptionEvent $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()));
}