You are here

class CustomPageExceptionHtmlSubscriber in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/EventSubscriber/CustomPageExceptionHtmlSubscriber.php \Drupal\Core\EventSubscriber\CustomPageExceptionHtmlSubscriber

Exception subscriber for handling core custom HTML error pages.

Hierarchy

Expanded class hierarchy of CustomPageExceptionHtmlSubscriber

1 file declares its use of CustomPageExceptionHtmlSubscriber
CustomPageExceptionHtmlSubscriberTest.php in core/tests/Drupal/Tests/Core/EventSubscriber/CustomPageExceptionHtmlSubscriberTest.php
Contains \Drupal\Tests\Core\EventSubscriber\CustomPageExceptionHtmlSubscriberTest.
1 string reference to 'CustomPageExceptionHtmlSubscriber'
core.services.yml in core/core.services.yml
core/core.services.yml
1 service uses CustomPageExceptionHtmlSubscriber
exception.custom_page_html in core/core.services.yml
Drupal\Core\EventSubscriber\CustomPageExceptionHtmlSubscriber

File

core/lib/Drupal/Core/EventSubscriber/CustomPageExceptionHtmlSubscriber.php, line 21
Contains \Drupal\Core\EventSubscriber\CustomPageExceptionHtmlSubscriber.

Namespace

Drupal\Core\EventSubscriber
View source
class CustomPageExceptionHtmlSubscriber extends DefaultExceptionHtmlSubscriber {

  /**
   * The configuration factory.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * The page alias manager.
   *
   * @var \Drupal\Core\Path\AliasManagerInterface
   */
  protected $aliasManager;

  /**
   * Constructs a new CustomPageExceptionHtmlSubscriber.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The configuration factory.
   * @param \Drupal\Core\Path\AliasManagerInterface $alias_manager
   *   The alias manager service.
   * @param \Symfony\Component\HttpKernel\HttpKernelInterface $http_kernel
   *   The HTTP Kernel service.
   * @param \Psr\Log\LoggerInterface $logger
   *   The logger service.
   * @param \Drupal\Core\Routing\RedirectDestinationInterface $redirect_destination
   *   The redirect destination service.
   */
  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;
  }

  /**
   * {@inheritdoc}
   */
  protected static function getPriority() {
    return -50;
  }

  /**
   * {@inheritdoc}
   */
  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);
  }

  /**
   * {@inheritdoc}
   */
  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);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CustomPageExceptionHtmlSubscriber::$aliasManager protected property The page alias manager.
CustomPageExceptionHtmlSubscriber::$configFactory protected property The configuration factory.
CustomPageExceptionHtmlSubscriber::getPriority protected static function Specifies the priority of all listeners in this class. Overrides DefaultExceptionHtmlSubscriber::getPriority
CustomPageExceptionHtmlSubscriber::on403 public function Handles a 403 error for HTML. Overrides DefaultExceptionHtmlSubscriber::on403
CustomPageExceptionHtmlSubscriber::on404 public function Handles a 404 error for HTML. Overrides DefaultExceptionHtmlSubscriber::on404
CustomPageExceptionHtmlSubscriber::__construct public function Constructs a new CustomPageExceptionHtmlSubscriber. Overrides DefaultExceptionHtmlSubscriber::__construct
DefaultExceptionHtmlSubscriber::$httpKernel protected property The HTTP kernel.
DefaultExceptionHtmlSubscriber::$logger protected property The logger instance.
DefaultExceptionHtmlSubscriber::$redirectDestination protected property The redirect destination service.
DefaultExceptionHtmlSubscriber::getHandledFormats protected function Specifies the request formats this subscriber will respond to. Overrides HttpExceptionSubscriberBase::getHandledFormats
DefaultExceptionHtmlSubscriber::makeSubrequest protected function Makes a subrequest to retrieve the default error page.
DefaultExceptionHtmlSubscriber::on401 public function Handles a 401 error for HTML.
HttpExceptionSubscriberBase::getSubscribedEvents public static function Registers the methods in this class that should be listeners. Overrides EventSubscriberInterface::getSubscribedEvents
HttpExceptionSubscriberBase::onException public function Handles errors for this subscriber.