CustomPageExceptionHtmlSubscriber.php in Zircon Profile 8
File
core/lib/Drupal/Core/EventSubscriber/CustomPageExceptionHtmlSubscriber.php
View source
<?php
namespace Drupal\Core\EventSubscriber;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Path\AliasManagerInterface;
use Drupal\Core\Routing\RedirectDestinationInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
class CustomPageExceptionHtmlSubscriber extends DefaultExceptionHtmlSubscriber {
protected $configFactory;
protected $aliasManager;
public function __construct(ConfigFactoryInterface $config_factory, AliasManagerInterface $alias_manager, HttpKernelInterface $http_kernel, LoggerInterface $logger, RedirectDestinationInterface $redirect_destination) {
parent::__construct($http_kernel, $logger, $redirect_destination);
$this->configFactory = $config_factory;
$this->aliasManager = $alias_manager;
}
protected static function getPriority() {
return -50;
}
public function on403(GetResponseForExceptionEvent $event) {
$path = $this->aliasManager
->getPathByAlias($this->configFactory
->get('system.site')
->get('page.403'));
$this
->makeSubrequest($event, trim($path, '/'), Response::HTTP_FORBIDDEN);
}
public function on404(GetResponseForExceptionEvent $event) {
$path = $this->aliasManager
->getPathByAlias($this->configFactory
->get('system.site')
->get('page.404'));
$this
->makeSubrequest($event, trim($path, '/'), Response::HTTP_NOT_FOUND);
}
}