From e5487493efecf2260e2b1132b92f62145509567b Mon Sep 17 00:00:00 2001
From: Joel Pittet <joel@pittet.ca>
Date: Wed, 21 May 2014 20:09:28 -0700
Subject: [PATCH] yay

---
 core/includes/theme.inc                            | 16 +----
 core/lib/Drupal/Core/Page/HtmlFragment.php         | 24 ++++++++
 core/lib/Drupal/Core/Template/RenderWrapper.php    | 70 ----------------------
 .../book/templates/book-export-html.html.twig      |  3 +-
 core/modules/system/templates/html.html.twig       | 12 ++--
 .../Drupal/Tests/Core/Common/RenderWrapperTest.php | 59 ------------------
 core/themes/bartik/bartik.theme                    |  1 -
 core/themes/seven/seven.theme                      |  1 -
 8 files changed, 34 insertions(+), 152 deletions(-)
 delete mode 100644 core/lib/Drupal/Core/Template/RenderWrapper.php
 delete mode 100644 core/tests/Drupal/Tests/Core/Common/RenderWrapperTest.php

diff --git a/core/includes/theme.inc b/core/includes/theme.inc
index e44f13d..a9561a4 100644
--- a/core/includes/theme.inc
+++ b/core/includes/theme.inc
@@ -20,7 +20,6 @@
 use Drupal\Core\Page\LinkElement;
 use Drupal\Core\Page\MetaElement;
 use Drupal\Core\Template\Attribute;
-use Drupal\Core\Template\RenderWrapper;
 use Drupal\Core\Theme\ThemeSettings;
 use Drupal\Component\Utility\NestedArray;
 use Drupal\Core\Render\Element;
@@ -2042,20 +2041,7 @@ function template_preprocess_html(&$variables) {
     }
   }
 
-  $variables['page_top'][] = array('#markup' => $page->getBodyTop());
-  $variables['page_bottom'][] = array('#markup' => $page->getBodyBottom());
-
-  // Add footer scripts as '#markup' so they can be rendered with other
-  // elements in page_bottom.
-  $footer_scripts = new RenderWrapper('drupal_get_js', array('footer'));
-  $variables['page_bottom'][] = array('#markup' => $footer_scripts);
-
-  // Wrap function calls in an object so they can be called when printed.
-  $variables['head'] = new RenderWrapper(function() use ($page) {
-    return implode("\n", $page->getMetaElements()) . implode("\n", $page->getLinkElements());
-  });
-  $variables['styles'] = new RenderWrapper('drupal_get_css');
-  $variables['scripts'] = new RenderWrapper('drupal_get_js');
+  $variables['html'] = $page;
 }
 
 /**
diff --git a/core/lib/Drupal/Core/Page/HtmlFragment.php b/core/lib/Drupal/Core/Page/HtmlFragment.php
index 18f587a..21c07ce 100644
--- a/core/lib/Drupal/Core/Page/HtmlFragment.php
+++ b/core/lib/Drupal/Core/Page/HtmlFragment.php
@@ -135,6 +135,30 @@ public function &getMetaElements() {
   }
 
   /**
+   * Returns a themed presentation of all JavaScript code for the current page.
+   *
+   * @return
+   *   All JavaScript code segments and includes for the scope as HTML tags.
+   *
+   * @see drupal_get_js()
+   */
+  public function getScripts($scope = 'header') {
+    return drupal_get_js($scope);
+  }
+
+  /**
+   * Returns a themed representation of all stylesheets to attach to the page.
+   *
+   * @return
+   *   A string of XHTML CSS tags.
+   *
+   * @see drupal_get_css()
+   */
+  public function getStyles() {
+    return drupal_get_css();
+  }
+
+  /**
    * Sets the response content.
    *
    * This should be the bulk of the page content, and will ultimately be placed
diff --git a/core/lib/Drupal/Core/Template/RenderWrapper.php b/core/lib/Drupal/Core/Template/RenderWrapper.php
deleted file mode 100644
index 7d7770d..0000000
--- a/core/lib/Drupal/Core/Template/RenderWrapper.php
+++ /dev/null
@@ -1,70 +0,0 @@
-<?php
-
-/**
- * @file
- * Contains \Drupal\Core\Template\RenderWrapper.
- */
-
-namespace Drupal\Core\Template;
-
-/**
- * A class that wraps functions to call them while printing in a template.
- *
- * To use, one may pass in the function name as a string followed by an array of
- * arguments to the constructor.
- * @code
- * $variables['scripts'] = new RenderWrapper('drupal_get_js', array('footer'));
- * @endcode
- */
-class RenderWrapper {
-
-  /**
-   * Stores the callback function to be called when rendered.
-   *
-   * @var callable
-   */
-  public $callback;
-
-  /**
-   * Stores the callback's arguments.
-   *
-   * @var array
-   */
-  public $args = array();
-
-  /**
-   * Constructs a RenderWrapper object.
-   *
-   * @param string $callback
-   *   The callback function name.
-   * @param array $args
-   *   The arguments to pass to the callback function.
-   */
-  public function __construct($callback, array $args = array()) {
-    if (!is_callable($callback)) {
-      throw new \InvalidArgumentException('Callback passed to RenderWrapper is not callable.');
-    }
-    $this->callback = $callback;
-    $this->args = $args;
-  }
-
-  /**
-   * Implements the magic __toString() method.
-   */
-  public function __toString() {
-    return $this->render();
-  }
-
-  /**
-   * Returns a string provided by the callback function.
-   *
-   * @return string
-   *   The results of the callback function.
-   */
-  public function render() {
-    if (!empty($this->callback) && is_callable($this->callback)) {
-      return call_user_func_array($this->callback, $this->args);
-    }
-  }
-
-}
diff --git a/core/modules/book/templates/book-export-html.html.twig b/core/modules/book/templates/book-export-html.html.twig
index 0fc8b1d..4766531 100644
--- a/core/modules/book/templates/book-export-html.html.twig
+++ b/core/modules/book/templates/book-export-html.html.twig
@@ -22,7 +22,8 @@
 <html{{ html_attributes }}>
   <head>
     <title>{{ title }}</title>
-    {{ head }}
+    {{ html.metaElements|join('\n') }}
+    {{ html.linkElements|join('\n') }}
     <base href="{{ base_url }}" />
     <link type="text/css" rel="stylesheet" href="misc/print.css" />
   </head>
diff --git a/core/modules/system/templates/html.html.twig b/core/modules/system/templates/html.html.twig
index 209b914..923ff3e 100644
--- a/core/modules/system/templates/html.html.twig
+++ b/core/modules/system/templates/html.html.twig
@@ -29,17 +29,19 @@
 <!DOCTYPE html>
 <html{{ html_attributes }}>
   <head>
-    {{ head }}
+    {{ html.metaElements|join('\n') }}
+    {{ html.linkElements|join('\n') }}
     <title>{{ head_title }}</title>
-    {{ styles }}
-    {{ scripts }}
+    {{ html.styles }}
+    {{ html.scripts }}
   </head>
   <body{{ attributes }}>
     <a href="#main-content" class="visually-hidden focusable skip-link">
       {{ 'Skip to main content'|t }}
     </a>
-    {{ page_top }}
+    {{ html.bodyTop }}
     {{ page }}
-    {{ page_bottom }}
+    {{ html.bodyBottom }}
+    {{ html.scripts('footer') }}
   </body>
 </html>
diff --git a/core/tests/Drupal/Tests/Core/Common/RenderWrapperTest.php b/core/tests/Drupal/Tests/Core/Common/RenderWrapperTest.php
deleted file mode 100644
index 1a1b568..0000000
--- a/core/tests/Drupal/Tests/Core/Common/RenderWrapperTest.php
+++ /dev/null
@@ -1,59 +0,0 @@
-<?php
-
-/**
- * @file
- * Contains \Drupal\Tests\Core\Common\RenderWrapperTest.
- */
-
-namespace Drupal\Tests\Core\Common;
-
-use Drupal\Tests\UnitTestCase;
-use Drupal\Core\Template\RenderWrapper;
-
-/**
- * Tests the \Drupal\Core\Template\RenderWrapper functionality.
- */
-class RenderWrapperTest extends UnitTestCase {
-
-  public static function getInfo() {
-    return array(
-      'name' => 'Render wrapper',
-      'description' => 'Tests the RenderWrapper class used for late rendering.',
-      'group' => 'Common',
-    );
-  }
-
-  /**
-   * Provides data for the RenderWrapper test.
-   *
-   * @return array
-   */
-  public function providerTestRenderWrapperData() {
-    return array(
-      array('ucwords', array('Amazingly few discotheques provide jukeboxes.'), 'Amazingly Few Discotheques Provide Jukeboxes.', 'Simple string manipulation callback.'),
-      array('phpversion', array(), phpversion(), 'Callback with no arguments.'),
-      array(array('Drupal\Component\Utility\String', 'checkPlain'), array('<script>'), '&lt;script&gt;', 'Namespaced callback.'),
-    );
-  }
-
-  /**
-   * Tests casting a RenderWrapper object to a string.
-   *
-   * @see \Drupal\Core\Template\RenderWrapper::__toString()
-   *
-   * @dataProvider providerTestRenderWrapperData
-   */
-  public function testDrupalRenderWrapper($callback, $arguments, $expected, $message) {
-    $this->assertSame($expected, (string) new RenderWrapper($callback, $arguments), $message);
-  }
-
-  /**
-   * Tests that an invalid callback throws an exception.
-   *
-   * @expectedException InvalidArgumentException
-   */
-  public function testInvalidCallback() {
-    new RenderWrapper(FALSE);
-  }
-
-}
diff --git a/core/themes/bartik/bartik.theme b/core/themes/bartik/bartik.theme
index 1532b9f..07e9bb7 100644
--- a/core/themes/bartik/bartik.theme
+++ b/core/themes/bartik/bartik.theme
@@ -6,7 +6,6 @@
  */
 
 use Drupal\Component\Utility\Xss;
-use Drupal\Core\Template\RenderWrapper;
 use Drupal\Core\Template\Attribute;
 
 /**
diff --git a/core/themes/seven/seven.theme b/core/themes/seven/seven.theme
index c3e7a32..80a268a 100644
--- a/core/themes/seven/seven.theme
+++ b/core/themes/seven/seven.theme
@@ -6,7 +6,6 @@
  */
 
 use Drupal\Component\Utility\Xss;
-use Drupal\Core\Template\RenderWrapper;
 use Drupal\Component\Utility\String;
 
 /**
-- 
1.9.3

