diff --git a/core/lib/Drupal/Core/CoreBundle.php b/core/lib/Drupal/Core/CoreBundle.php index 33dd3f9..d7d23ba 100644 --- a/core/lib/Drupal/Core/CoreBundle.php +++ b/core/lib/Drupal/Core/CoreBundle.php @@ -215,8 +215,7 @@ public function build(ContainerBuilder $container) { ->addTag('event_subscriber'); $container->register('content_negotiation', 'Drupal\Core\ContentNegotiation'); $container->register('html_view_subscriber', 'Drupal\Core\EventSubscriber\HtmlViewSubscriber') - // @todo for some reason, this injection fails during test runs. - // ->addArgument(new Reference('module_handler')) + ->addArgument(new Reference('module_handler')) ->addTag('event_subscriber'); $container->register('view_subscriber', 'Drupal\Core\EventSubscriber\ViewSubscriber') ->addArgument(new Reference('content_negotiation')) diff --git a/core/lib/Drupal/Core/EventSubscriber/HtmlViewSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/HtmlViewSubscriber.php index f483d3a..8383d8e 100644 --- a/core/lib/Drupal/Core/EventSubscriber/HtmlViewSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/HtmlViewSubscriber.php @@ -26,7 +26,6 @@ * with assets and wrapping the in the skeletal HTML, primarily the tag * and its contents. * - * @todo making this work for blocks, which are inherently partial responses, is a little weird. */ class HtmlViewSubscriber implements EventSubscriberInterface { @@ -35,10 +34,9 @@ class HtmlViewSubscriber implements EventSubscriberInterface { */ protected $moduleHandler; -// @todo for some reason, this injection fails during test runs. -// public function __construct(ModuleHandlerInterface $moduleHandler) { -// $this->moduleHandler = $moduleHandler; -// } + public function __construct(ModuleHandlerInterface $moduleHandler) { + $this->moduleHandler = $moduleHandler; + } /** * Processes a specialized Drupal Response into fully-formed HTML. @@ -62,23 +60,18 @@ 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'); - - // Modules can add elements to $page as needed in hook_page_build(). - foreach (module_implements('page_build') as $module) { - // foreach ($this->moduleHandler->getImplementations('page_build') as $module) { + foreach ($this->moduleHandler->getImplementations('page_build') as $module) { $function = $module . '_page_build'; $function($page); } + $this->moduleHandler->alter('page', $page); - drupal_alter('page', $page); - // $this->moduleHandler->alter('page', $page); - - // @todo three cheers for hacky passthroughs. + // @todo these are horrible passthrough hacks; remove them incrementally as we implement the respective pieces elsewhere. $vars = array( 'page' => array( '#type' => 'markup', '#markup' => $response->getContent(), - '#children' => $response->getContent(), + '#children' => $response->getContent(), // @todo some preprocessors demand this be here 'page_top' => empty($page['page_top']) ? array(): $page['page_top'], 'page_bottom' => empty($page['page_bottom']) ? array(): $page['page_bottom'], ), diff --git a/core/lib/Drupal/Core/PartialResponse.php b/core/lib/Drupal/Core/PartialResponse.php index d4ef068..43694b0 100644 --- a/core/lib/Drupal/Core/PartialResponse.php +++ b/core/lib/Drupal/Core/PartialResponse.php @@ -22,6 +22,13 @@ class PartialResponse { */ protected $content; + /** + * The title of this PartialResponse. + * + * @var string + */ + protected $title = ''; + public function __construct($content = '') { $this->content = $content; } @@ -52,4 +59,70 @@ public function setContent($content) { public function getContent() { return $this->content; } + + /** + * Adds another meta tag, to be output in HTML head. + * + * @param $tag + */ + public function addMetaTag($tag) { + // @todo implement this + } + + /** + * Gets all meta tags for output. + */ + public function getMetaTags() { + // @todo implement this + } + + /** + * Sets the title of this PartialResponse. + * + * 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. + */ + public function setTitle($title, $output = CHECK_PLAIN) { + $this->title = ($output == PASS_THROUGH) ? $title : check_plain($title); + } + + /** + * Indicates whether or not this PartialResponse has a title. + * + * @return bool + */ + public function hasTitle() { + return !empty($this->title); + } + + /** + * Gets the title for this PartialResponse, if any. + * + * @return string + */ + public function getTitle() { + return $this->title; + } + + /** + * Sets the AssetBag for this PartialResponse. + * + * The AssetBag has all of its own logic for sorting out assets and deciding + * where they should go; the PartialResponse is only response for carrying it + * around. + * + * @todo https://drupal.org/node/1762204 + */ + public function setAssetBag() { + + } + + /** + * Returns the AssetBag contained by this PartialResponse. + */ + public function getAssetBag() { + + } } 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 ded6f23..caa73c2 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/PartialResponseTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Common/PartialResponseTest.php @@ -21,25 +21,34 @@ class PartialResponseTest extends WebTestBase { public static function getInfo() { return array( - 'name' => 'Partial Response to HTML', + 'name' => 'Partial HTML Response', 'description' => 'Tests that PartialResponse data is properly rendered into the html template.', 'group' => 'Common', // @todo put me somewhere better ); } /** - * Tests that a PartialResponse object is rendered correctly. + * Tests that a PartialResponse object is rendered correctly by issuing a web + * request against it. */ - public function testPartialResponseRendering() { - // First, test it with a direct request. + public function testPartialResponseByWeb() { $this->drupalGet('html_test'); + + // 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.'); + } - // Now, mock up a kernel and test it that way, too. - $kernel = drupal_container()->get('http_kernel'); + /** + * Tests that a PartialResponse object is rendered correctly by mocking the + * environment. + */ + public function testPartialResponseByUnit() { + $kernel = $this->container->get('http_kernel'); $request = Request::create('/foo'); $response = new PartialResponse('hello world'); - $subscriber = new HtmlViewSubscriber(drupal_container()->get('module_handler')); + $subscriber = new HtmlViewSubscriber($this->container->get('module_handler')); $event = new GetResponseForControllerResultEvent($kernel, $request, HttpKernel::MASTER_REQUEST, $response); $subscriber->onPartialHtmlResponse($event); $this->assertTrue(preg_match('/hello world/', $event->getResponse()->getContent()), 'Expected raw output found within HTML response.'); diff --git a/core/modules/system/tests/modules/html_test/html_test.module b/core/modules/system/tests/modules/html_test/html_test.module index 52c8e36..ea3dfb5 100644 --- a/core/modules/system/tests/modules/html_test/html_test.module +++ b/core/modules/system/tests/modules/html_test/html_test.module @@ -1,4 +1,4 @@