function ExceptionDetectNeedsInstallSubscriber::onException

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/EventSubscriber/ExceptionDetectNeedsInstallSubscriber.php \Drupal\Core\EventSubscriber\ExceptionDetectNeedsInstallSubscriber::onException()
  2. 8.9.x core/lib/Drupal/Core/EventSubscriber/ExceptionDetectNeedsInstallSubscriber.php \Drupal\Core\EventSubscriber\ExceptionDetectNeedsInstallSubscriber::onException()
  3. 10 core/lib/Drupal/Core/EventSubscriber/ExceptionDetectNeedsInstallSubscriber.php \Drupal\Core\EventSubscriber\ExceptionDetectNeedsInstallSubscriber::onException()

Handles errors for this subscriber.

Parameters

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

File

core/lib/Drupal/Core/EventSubscriber/ExceptionDetectNeedsInstallSubscriber.php, line 41

Class

ExceptionDetectNeedsInstallSubscriber
Exception handler to determine if an exception indicates an uninstalled site.

Namespace

Drupal\Core\EventSubscriber

Code

public function onException(ExceptionEvent $event) {
    $exception = $event->getThrowable();
    if ($this->shouldRedirectToInstaller($exception, $this->connection)) {
        // Only redirect if this is an HTML response (i.e., a user trying to view
        // the site in a web browser before installing it).
        $request = $event->getRequest();
        $format = $request->query
            ->get(MainContentViewSubscriber::WRAPPER_FORMAT, $request->getRequestFormat());
        if ($format == 'html') {
            $event->setResponse(new RedirectResponse($request->getBasePath() . '/core/install.php', 302, [
                'Cache-Control' => 'no-cache',
            ]));
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.