You are here

public function WebformExceptionHtmlSubscriber::on403RedirectPrivateFileAccess in Webform 8.5

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

Redirect to user login when access is denied to private webform file.

Parameters

\Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event: The event to process.

See also

webform_file_download()

\Drupal\webform\Plugin\WebformElement\WebformManagedFileBase::accessFileDownload

1 call to WebformExceptionHtmlSubscriber::on403RedirectPrivateFileAccess()
WebformExceptionHtmlSubscriber::on403 in src/EventSubscriber/WebformExceptionHtmlSubscriber.php
Handles a 403 error for HTML.

File

src/EventSubscriber/WebformExceptionHtmlSubscriber.php, line 135

Class

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

Namespace

Drupal\webform\EventSubscriber

Code

public function on403RedirectPrivateFileAccess(GetResponseForExceptionEvent $event) {
  $path = $event
    ->getRequest()
    ->getPathInfo();

  // Make sure the user is trying to access a private webform file upload.
  if (strpos($path, '/system/files/webform/') !== 0) {
    return;
  }

  // Make private webform file upload is not a temporary file.
  // @see \Drupal\webform\Plugin\WebformElement\WebformManagedFileBase::postSave
  if (strpos($path, '/_sid_/') !== FALSE) {
    return;
  }

  // Check that private file redirection is enabled.
  if (!$this->configFactory
    ->get('webform.settings')
    ->get('file.file_private_redirect')) {
    return;
  }
  $message = $this->configFactory
    ->get('webform.settings')
    ->get('file.file_private_redirect_message');
  $this
    ->redirectToLogin($event, $message);
}