function Fast404ExceptionHtmlSubscriber::on404
Same name in other branches
- 9 core/lib/Drupal/Core/EventSubscriber/Fast404ExceptionHtmlSubscriber.php \Drupal\Core\EventSubscriber\Fast404ExceptionHtmlSubscriber::on404()
- 10 core/lib/Drupal/Core/EventSubscriber/Fast404ExceptionHtmlSubscriber.php \Drupal\Core\EventSubscriber\Fast404ExceptionHtmlSubscriber::on404()
- 11.x core/lib/Drupal/Core/EventSubscriber/Fast404ExceptionHtmlSubscriber.php \Drupal\Core\EventSubscriber\Fast404ExceptionHtmlSubscriber::on404()
Handles a 404 error for HTML.
Parameters
\Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event: The event to process.
File
-
core/
lib/ Drupal/ Core/ EventSubscriber/ Fast404ExceptionHtmlSubscriber.php, line 68
Class
- Fast404ExceptionHtmlSubscriber
- High-performance 404 exception subscriber.
Namespace
Drupal\Core\EventSubscriberCode
public function on404(GetResponseForExceptionEvent $event) {
$request = $event->getRequest();
$config = $this->configFactory
->get('system.performance');
$exclude_paths = $config->get('fast_404.exclude_paths');
if ($config->get('fast_404.enabled') && $exclude_paths && !preg_match($exclude_paths, $request->getPathInfo())) {
$fast_paths = $config->get('fast_404.paths');
if ($fast_paths && preg_match($fast_paths, $request->getPathInfo())) {
$fast_404_html = strtr($config->get('fast_404.html'), [
'@path' => Html::escape($request->getUri()),
]);
$response = new Response($fast_404_html, Response::HTTP_NOT_FOUND);
$event->setResponse($response);
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.