Issue #1975442 by thedavidmeister, dcam: Fixed drupal_render() should always return a string.
parent
f019275be7
commit
68f6a7c857
|
@ -1,6 +1,8 @@
|
|||
|
||||
Drupal 7.23, xxxx-xx-xx (development version)
|
||||
-----------------------
|
||||
- Fixed drupal_render() to always return an empty string when there is no
|
||||
output, rather than sometimes returning NULL (minor API change).
|
||||
- Added protection to cache_clear_all() to ensure that non-cache tables cannot
|
||||
be truncated (API addition: a new isValidBin() method has been added to the
|
||||
default database cache implementation).
|
||||
|
|
|
@ -5795,23 +5795,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.
|
||||
|
@ -5847,7 +5847,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.
|
||||
|
|
|
@ -1564,6 +1564,60 @@ class DrupalRenderTestCase extends DrupalWebTestCase {
|
|||
parent::setUp('common_test');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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().');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test sorting by weight.
|
||||
*/
|
||||
|
|
|
@ -100,6 +100,14 @@ function common_test_destination() {
|
|||
print "The destination: " . check_plain($destination['destination']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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().
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue