diff --git a/core/includes/common.inc b/core/includes/common.inc index a4da21b..f5d1ff9 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -3633,7 +3633,7 @@ function drupal_render_cache_get(array $elements) { * * @see drupal_render_cache_get() */ -function drupal_render_cache_set(&$markup, array $elements) { +function drupal_render_cache_set(&$markup, $elements) { // Create the cache ID for the element. if (!\Drupal::request()->isMethodSafe() || !$cid = drupal_render_cid_create($elements)) { return FALSE; @@ -3729,7 +3729,7 @@ function drupal_render_cache_generate_placeholder($callback, array &$context) { * @see drupal_render() * @see drupal_render_collect_post_render_cache */ -function _drupal_render_process_post_render_cache(array &$elements) { +function _drupal_render_process_post_render_cache(&$elements) { if (isset($elements['#post_render_cache'])) { /** @var \Drupal\Core\Controller\ControllerResolverInterface $controller_resolver */ $controller_resolver = \Drupal::service('controller_resolver'); diff --git a/core/modules/system/src/Tests/Common/RenderTest.php b/core/modules/system/src/Tests/Common/RenderTest.php index 7587af6..bf43051 100644 --- a/core/modules/system/src/Tests/Common/RenderTest.php +++ b/core/modules/system/src/Tests/Common/RenderTest.php @@ -11,6 +11,7 @@ use Drupal\Component\Utility\Html; use Drupal\Core\Render\Element; use Drupal\simpletest\DrupalUnitTestBase; +use Drupal\common_test\RenderableArray; /** * Tests drupal_render(). @@ -282,6 +283,40 @@ function testDrupalRenderBasics() { } /** + * Tests the output drupal_render() using objects instead of arrays. + */ + function testDrupalRenderArrayObjects() { + // Simplest case, a single object. + $types[] = array( + 'name' => 'Simple renderable object', + 'value' => new RenderableArray(array('#markup' => 'Hello World')), + 'expected' => 'Hello World', + ); + // Two renderable objects + $types[] = array( + 'name' => 'Array with two renderable objects', + 'value' => array( + 'hello' => new RenderableArray(array('#markup' => 'Hello', '#suffix' => ' ')), + 'world' => new RenderableArray(array('#markup' => 'World')), + ), + 'expected' => 'Hello World', + ); + // More complex, mixed nested objects and arrays + $render = new RenderableArray(); + $render['hello'] = new RenderableArray(array('#markup' => 'Hello', '#suffix' => ' ')); + $render['world'] = array('#markup' => 'World'); + $types[] = array( + 'name' => 'Nested renderable objects', + 'value' => $render, + 'expected' => 'Hello World', + ); + foreach($types as $type) { + $this->assertIdentical(drupal_render($type['value']), $type['expected'], '"' . $type['name'] . '" input rendered correctly by drupal_render().'); + } + } + + + /** * Tests sorting by weight. */ function testDrupalRenderSorting() {