Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By ekl1773 on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x
Issue links:
Description:
- _theme() now returns FALSE when the theme hook/suggestion passed to theme() is not found in the registry; otherwise _theme() returns the return value of the theme function/template.
- drupal_render() will explicitly check for a FALSE return from _theme() before rendering children or #markup. drupal_render() only attempts to handle child elements and #markup if _theme() never built markup via a theme function or template.
Before:
<?php
// Output is 'foo'
$empty = array(
'#theme' => 'theme_returns_empty',
'#markup' => 'foo',
);
// Output is 'foo'
$empty = array(
'#theme' => 'theme_returns_empty',
'child' => array('#markup' => 'foo'),
);
// Output is 'foo'
$not_implemented = array(
'#theme' => array('theme_not_implemented'),
'#markup' => 'foo',
);
?>
After:
<?php
// _theme() intentionally returns an empty string. This should not be considered a falsey value. Output is '' (an empty string).
// Do not back off to the #markup key value.
$empty = array(
'#theme' => array('theme_returns_empty'),
'#markup' => 'foo',
);
// Output is '' (an empty string)
// Do not back off to the #markup key value.
$empty = array(
'#theme' => 'theme_returns_empty',
'child' => array('#markup' => 'foo'),
);
// The theme function is not implemented, so theme() returns FALSE. Output is 'foo'
// Back off to the #markup key value.
$not_implemented = array(
'#theme' => array('theme_not_implemented'),
'#markup' => 'foo',
);
?>
Impacts:
Themers