diff --git a/core/lib/Drupal/Core/EventSubscriber/CustomPageExceptionHtmlSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/CustomPageExceptionHtmlSubscriber.php index c393a34..96bd6d8 100644 --- a/core/lib/Drupal/Core/EventSubscriber/CustomPageExceptionHtmlSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/CustomPageExceptionHtmlSubscriber.php @@ -63,7 +63,7 @@ protected static function getPriority() { */ public function on403(GetResponseForExceptionEvent $event) { $path = $this->aliasManager->getPathByAlias($this->configFactory->get('system.site')->get('page.403')); - $this->makeSubrequest($event, $path, Response::HTTP_FORBIDDEN); + $this->makeSubrequest($event, $event->getRequest()->getBaseUrl() . $path, Response::HTTP_FORBIDDEN); } /** @@ -71,7 +71,7 @@ public function on403(GetResponseForExceptionEvent $event) { */ public function on404(GetResponseForExceptionEvent $event) { $path = $this->aliasManager->getPathByAlias($this->configFactory->get('system.site')->get('page.404')); - $this->makeSubrequest($event, $path, Response::HTTP_NOT_FOUND); + $this->makeSubrequest($event, $event->getRequest()->getBaseUrl() . $path, Response::HTTP_NOT_FOUND); } } diff --git a/core/lib/Drupal/Core/EventSubscriber/DefaultExceptionHtmlSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/DefaultExceptionHtmlSubscriber.php index 9535abf..06073ea 100644 --- a/core/lib/Drupal/Core/EventSubscriber/DefaultExceptionHtmlSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/DefaultExceptionHtmlSubscriber.php @@ -7,6 +7,7 @@ namespace Drupal\Core\EventSubscriber; +use Drupal\Core\Url; use Drupal\Core\Utility\Error; use Psr\Log\LoggerInterface; use Symfony\Component\HttpFoundation\Request; @@ -69,7 +70,7 @@ protected function getHandledFormats() { * The event to process. */ public function on403(GetResponseForExceptionEvent $event) { - $this->makeSubrequest($event, 'system/403', Response::HTTP_FORBIDDEN); + $this->makeSubrequest($event, Url::fromRoute('system.403')->toString(), Response::HTTP_FORBIDDEN); } /** @@ -79,7 +80,7 @@ public function on403(GetResponseForExceptionEvent $event) { * The event to process. */ public function on404(GetResponseForExceptionEvent $event) { - $this->makeSubrequest($event, 'system/404', Response::HTTP_NOT_FOUND); + $this->makeSubrequest($event, Url::fromRoute('system.404')->toString(), Response::HTTP_NOT_FOUND); } /** @@ -87,24 +88,22 @@ public function on404(GetResponseForExceptionEvent $event) { * * @param \Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event * The event to process - * @param string $path - * The path to which to make a subrequest for this error message. + * @param string $url + * The url to which to make a subrequest for this error message. * @param int $status_code * The status code for the error being handled. */ - protected function makeSubrequest(GetResponseForExceptionEvent $event, $path, $status_code) { + protected function makeSubrequest(GetResponseForExceptionEvent $event, $url, $status_code) { $request = $event->getRequest(); - // @todo Remove dependency on the internal _system_path attribute: - // https://www.drupal.org/node/2293523. - $system_path = $request->attributes->get('_system_path'); + $current_url = $request->getUri(); - if ($path && $path != $system_path) { + if ($url && $url != $current_url) { if ($request->getMethod() === 'POST') { - $sub_request = Request::create($request->getBaseUrl() . '/' . $path, 'POST', ['destination' => $system_path, '_exception_statuscode' => $status_code] + $request->request->all(), $request->cookies->all(), [], $request->server->all()); + $sub_request = Request::create($url, 'POST', drupal_get_destination() + ['_exception_statuscode' => $status_code] + $request->request->all(), $request->cookies->all(), [], $request->server->all()); } else { - $sub_request = Request::create($request->getBaseUrl() . '/' . $path, 'GET', $request->query->all() + ['destination' => $system_path, '_exception_statuscode' => $status_code], $request->cookies->all(), [], $request->server->all()); + $sub_request = Request::create($url, 'GET', $request->query->all() + drupal_get_destination() + ['_exception_statuscode' => $status_code], $request->cookies->all(), [], $request->server->all()); } try {