diff --git a/core/includes/common.inc b/core/includes/common.inc index 4087a42..654d849 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -5164,23 +5164,23 @@ function drupal_render_page($page) { * array to be rendered independently and prevents them from being rendered * more than once on subsequent calls to drupal_render() (e.g., as part of a * larger array). If the same array or array element is passed more than once - * to drupal_render(), it simply returns a NULL value. + * to drupal_render(), it simply returns an empty string. * - * @param $elements + * @param array $elements * The structured array describing the data to be rendered. * - * @return + * @return string * The rendered HTML. */ function drupal_render(&$elements) { // Early-return nothing if user does not have access. if (empty($elements) || (isset($elements['#access']) && !$elements['#access'])) { - return; + return ''; } // Do not print elements twice. if (!empty($elements['#printed'])) { - return; + return ''; } // Try to fetch the element's markup from cache and return. @@ -5214,7 +5214,7 @@ function drupal_render(&$elements) { // Allow #pre_render to abort rendering. if (!empty($elements['#printed'])) { - return; + return ''; } // Get the children of the element, sorted by weight. diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/RenderTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/RenderTest.php index 8e053f9..31e4f34 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/RenderTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Common/RenderTest.php @@ -30,6 +30,60 @@ public static function getInfo() { } /** + * Tests the output drupal_render() for some elementary input values. + */ + function testDrupalRenderBasics() { + $types = array( + array( + 'name' => 'null', + 'value' => NULL, + 'expected' => '', + ), + array( + 'name' => 'no value', + 'expected' => '', + ), + array( + 'name' => 'empty string', + 'value' => '', + 'expected' => '', + ), + array( + 'name' => 'no access', + 'value' => array( + '#markup' => 'foo', + '#access' => FALSE, + ), + 'expected' => '', + ), + array( + 'name' => 'previously printed', + 'value' => array( + '#markup' => 'foo', + '#printed' => TRUE, + ), + 'expected' => '', + ), + array( + 'name' => 'printed in prerender', + 'value' => array( + '#markup' => 'foo', + '#pre_render' => array('common_test_drupal_render_printing_pre_render'), + ), + 'expected' => '', + ), + array( + 'name' => 'basic renderable array', + 'value' => array('#markup' => 'foo'), + 'expected' => 'foo', + ), + ); + 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() { diff --git a/core/modules/system/tests/modules/common_test/common_test.module b/core/modules/system/tests/modules/common_test/common_test.module index 203ead2..3670d41 100644 --- a/core/modules/system/tests/modules/common_test/common_test.module +++ b/core/modules/system/tests/modules/common_test/common_test.module @@ -148,6 +148,14 @@ function common_test_drupal_render_invalid_keys() { } /** + * Applies #printed to an element to help test #pre_render. + */ +function common_test_drupal_render_printing_pre_render($elements) { + $elements['#printed'] = TRUE; + return $elements; +} + +/** * Implements hook_TYPE_alter(). */ function common_test_drupal_alter_alter(&$data, &$arg2 = NULL, &$arg3 = NULL) {