Commit c6edf7dd authored by webchick's avatar webchick

Issue #1975442 by thedavidmeister: Change notice: drupal_render() should always return a string.

parent f8df0fed
......@@ -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.
......
......@@ -29,6 +29,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.
*/
......
......@@ -147,6 +147,14 @@ function common_test_drupal_render_invalid_keys() {
return drupal_render($element);
}
/**
* 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().
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment