diff --git a/core/lib/Drupal/Core/EventSubscriber/HtmlViewSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/HtmlViewSubscriber.php index c777a33..de93a32 100644 --- a/core/lib/Drupal/Core/EventSubscriber/HtmlViewSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/HtmlViewSubscriber.php @@ -2,7 +2,7 @@ /** * @file - * Definition of Drupal\Core\EventSubscriber\HtmlViewSubscriber. + * Contains \Drupal\Core\EventSubscriber\HtmlViewSubscriber. */ namespace Drupal\Core\EventSubscriber; @@ -19,13 +19,12 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** - * Subscriber for for VIEW HTTP events that finishes a Drupal HTML response. + * Subscriber for KernelEvents::VIEW events that finalizes an HTML response. * - * This subscriber takes a partial response, the sort generated by a block or + * This subscriber takes a PartialResponse, the sort generated by a block or * layout-driven route, and marshals it into a full Response object by dealing * with assets and wrapping the in the skeletal HTML, primarily the tag * and its contents. - * */ class HtmlViewSubscriber implements EventSubscriberInterface { @@ -50,7 +49,7 @@ public function __construct(ModuleHandlerInterface $moduleHandler) { * @param \Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent $event * The Event to process. * - * @return \Symfony\Component\HttpFoundation\Response; + * @return \Symfony\Component\HttpFoundation\Response */ public function onPartialHtmlResponse(GetResponseForControllerResultEvent $event) { // Only act if we have a specialized Drupal response to work with. @@ -60,7 +59,8 @@ public function onPartialHtmlResponse(GetResponseForControllerResultEvent $event // @todo this is really lazy, but the easiest way to get $page_{top,bottom}. this can be removed once the responsibility is shifted into displays/controllers $page = element_info('page'); - + // We only do this hack for a main request because a subrequest would be a + // block, and thus doesn't need page-level variables. if ($event->getRequestType() === HttpKernelInterface::MASTER_REQUEST) { foreach ($this->moduleHandler->getImplementations('page_build') as $module) { $function = $module . '_page_build'; @@ -80,7 +80,7 @@ public function onPartialHtmlResponse(GetResponseForControllerResultEvent $event ); $event->setResponse(new Response(theme('html', $vars))); - // Stop propagation, as the ViewSubscriber will handle this poorly. + // Stop propagation; the ViewSubscriber is expecting a string, $event->stopPropagation(); } diff --git a/core/lib/Drupal/Core/EventSubscriber/ViewSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/ViewSubscriber.php index ccdb595..c9da4e4 100644 --- a/core/lib/Drupal/Core/EventSubscriber/ViewSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/ViewSubscriber.php @@ -47,6 +47,12 @@ public function onView(GetResponseForControllerResultEvent $event) { $request = $event->getRequest(); + // This expects either strings or arrays; it does not handle objects. Bail + // out if the controller result is any kind of object. + if (is_object($event->getControllerResult())) { + return; + } + // For a master request, we process the result and wrap it as needed. // For a subrequest, all we want is the string value. We assume that // is just an HTML string from a controller, so wrap that into a response diff --git a/core/lib/Drupal/Core/PartialResponse.php b/core/lib/Drupal/Core/PartialResponse.php index 8976e64..d82f82c 100644 --- a/core/lib/Drupal/Core/PartialResponse.php +++ b/core/lib/Drupal/Core/PartialResponse.php @@ -2,7 +2,7 @@ /** * @file - * Definition of Drupal\Core\PartialResponse. + * Contains \Drupal\Core\PartialResponse. */ namespace Drupal\Core; @@ -10,7 +10,7 @@ /** * Response object that contains variables for injection into the html template. * - * @todo move these methods into an interface. + * @todo should we have this conform to an interface? https://drupal.org/node/1871596#comment-7134686 * @todo add method replacements for *all* data sourced by html.tpl.php */ class PartialResponse { @@ -52,7 +52,7 @@ public function setContent($content) { } /** - * Gets the main content of this Response. + * Gets the main content of this PartialResponse. * * @return string */ @@ -66,7 +66,7 @@ public function getContent() { * Handling of this title varies depending on what is consuming this * PartialResponse object. If it's a block, it may only be used as the block's * title; if it's at the page level, it will be used in a number of places, - * including the title in HTML head. + * including the html title. */ public function setTitle($title, $output = CHECK_PLAIN) { $this->title = ($output == PASS_THROUGH) ? $title : check_plain($title); diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/PartialResponseTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/PartialResponseTest.php index caa73c2..641b0d9 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/PartialResponseTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Common/PartialResponseTest.php @@ -1,7 +1,7 @@ 'Partial HTML Response', - 'description' => 'Tests that PartialResponse data is properly rendered into the html template.', + 'description' => 'Tests that PartialResponse data is properly rendered into html.tpl.php.', 'group' => 'Common', // @todo put me somewhere better ); } /** - * Tests that a PartialResponse object is rendered correctly by issuing a web - * request against it. + * Tests that a PartialResponse object is rendered correctly by issuing an + * HTTP request against it. */ public function testPartialResponseByWeb() { $this->drupalGet('html_test'); - // Check that our basic body text is there + // Check that our basic body text is there. $this->assertRaw('hello world'); // Check that we didn't get a page within a page, inception-style. $this->assertNoPattern('#.*#s', 'There was no double-page effect from a misrendered subrequest.');