From 0faa5ce3c3207e7580ee3741b213ee43d2adbc5d Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole Date: Thu, 23 Oct 2014 20:32:54 +0100 Subject: [PATCH] git commit -m Issue --- .../FinishResponseSubscriber.php | 12 +++++++++-- .../src/EventSubscriber/RouteSubscriber.php | 20 ------------------- .../src/Plugin/views/area/HTTPStatusCode.php | 4 ++-- 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php index 42600fd4cd6..fb68b07a042 100644 --- a/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php @@ -98,10 +98,18 @@ class FinishResponseSubscriber implements EventSubscriberInterface { // Attach globally-declared headers to the response object so that Symfony // can send them for us correctly. - // @todo remove this once we have removed all _drupal_add_http_header() - // calls. + // @todo Remove this once drupal_process_attached() no longer calls + // _drupal_add_http_header(), which has its own static. Instead, + // _drupal_process_attached() should use + // \Symfony\Component\HttpFoundation\Response->headers->set(), which is + // already documented on the (deprecated) _drupal_process_attached() to + // become the final, intended mechanism. $headers = drupal_get_http_header(); foreach ($headers as $name => $value) { + // Symfony special-cases the 'Status' header. + if ($name === 'status') { + $response->setStatusCode($value); + } $response->headers->set($name, $value, FALSE); } diff --git a/core/modules/views/src/EventSubscriber/RouteSubscriber.php b/core/modules/views/src/EventSubscriber/RouteSubscriber.php index f1f02b38797..abc5bb62695 100644 --- a/core/modules/views/src/EventSubscriber/RouteSubscriber.php +++ b/core/modules/views/src/EventSubscriber/RouteSubscriber.php @@ -7,7 +7,6 @@ namespace Drupal\views\EventSubscriber; -use Drupal\Core\Page\HtmlPage; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\State\StateInterface; use Drupal\Core\Routing\RouteSubscriberBase; @@ -26,7 +25,6 @@ use Symfony\Component\HttpKernel\KernelEvents; * routes are overridden by views. This information is used to determine which * views have to be added by views in the dynamic event. * - * Additional to adding routes it also changes the htmlpage response code. * * @see \Drupal\views\Plugin\views\display\PathPluginBase */ @@ -85,7 +83,6 @@ class RouteSubscriber extends RouteSubscriberBase { */ public static function getSubscribedEvents() { $events = parent::getSubscribedEvents(); - $events[KernelEvents::VIEW][] = array('onHtmlPage', 75); $events[RoutingEvents::FINISHED] = array('routeRebuildFinished'); // Ensure to run after the entity resolver subscriber // @see \Drupal\Core\EventSubscriber\EntityRouteAlterSubscriber @@ -113,23 +110,6 @@ class RouteSubscriber extends RouteSubscriberBase { return $this->viewsDisplayPairs; } - /** - * Sets the proper response code coming from the http status area handler. - * - * @param \Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent $event - * The Event to process. - * - * @see \Drupal\views\Plugin\views\area\HTTPStatusCode - */ - public function onHtmlPage(GetResponseForControllerResultEvent $event) { - $page = $event->getControllerResult(); - if ($page instanceof HtmlPage) { - if (($request = $event->getRequest()) && $request->attributes->has('view_id')) { - $page->setStatusCode($request->attributes->get('_http_statuscode', 200)); - }; - } - } - /** * Returns a set of route objects. * diff --git a/core/modules/views/src/Plugin/views/area/HTTPStatusCode.php b/core/modules/views/src/Plugin/views/area/HTTPStatusCode.php index 0f7756d8adb..036e369c631 100644 --- a/core/modules/views/src/Plugin/views/area/HTTPStatusCode.php +++ b/core/modules/views/src/Plugin/views/area/HTTPStatusCode.php @@ -64,8 +64,8 @@ class HTTPStatusCode extends AreaPluginBase { */ function render($empty = FALSE) { if (!$empty || !empty($this->options['empty'])) { - $this->view->getResponse()->setStatusCode($this->options['status_code']); - $this->view->getRequest()->attributes->set('_http_statuscode', $this->options['status_code']); + $build['#attached']['http_header'][] = ['Status', $this->options['status_code']]; + return $build; } }