From c281a1279548ad7d16caf504ee3ad2346eaa0d7d Mon Sep 17 00:00:00 2001 From: David Meister Date: Sun, 9 Jun 2013 20:13:56 +1000 Subject: [PATCH] 2012812-20 --- core/includes/common.inc | 37 +++++++++++++--------- core/includes/theme.inc | 5 ++- .../lib/Drupal/system/Tests/Theme/ThemeTest.php | 2 +- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/core/includes/common.inc b/core/includes/common.inc index 00decfa..cb7d4ac 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -4800,31 +4800,38 @@ function drupal_render(&$elements) { // Initialize this element's #children, unless a #pre_render callback already // preset #children. if (!isset($elements['#children'])) { - $elements['#children'] = ''; + $elements['#children'] = NULL; } // Call the element's #theme function if it is set. Then any children of the // element have to be rendered there. If the internal #render_children // property is set, do not call the #theme function to prevent infinite // recursion. + $theme_is_implemented = FALSE; if (isset($elements['#theme']) && !isset($elements['#render_children'])) { $elements['#children'] = theme($elements['#theme'], $elements); - } - // If #theme was not set and the element has children, render them now. - // This is the same process as drupal_render_children() but is inlined - // for speed. - if ($elements['#children'] === '') { + // If theme() returns NULL this means that the hook in #theme was not found + // in the registry. This is common for theme suggestions. + $theme_is_implemented = isset($elements['#children']); + } + // #theme is either not set or does not exist in the registry. + if (!$theme_is_implemented) { + // If #theme is not implemented and the element has children, render them + // now. This is the same process as drupal_render_children() but is inlined + // for speed. foreach ($children as $key) { $elements['#children'] .= drupal_render($elements[$key]); } - } - // If #theme was not set, but the element has raw #markup, prepend the content - // in #markup to #children. #children may contain the rendered content - // supplied by #theme, or the rendered child elements, as processed above. If - // both #theme and #markup are set, then #theme is responsible for rendering - // the element. Eventually assigned #theme_wrappers will expect both the - // element's #markup and the rendered content of child elements in #children. - if (!isset($elements['#theme']) && isset($elements['#markup'])) { - $elements['#children'] = $elements['#markup'] . $elements['#children']; + + // If #theme is not implemented and the element has raw #markup as a + // fallback, prepend the content in #markup to #children. In this case + // #children will contain whatever is provided by #pre_render prepended to + // what is rendered recursively above. If #theme is implemented then it is + // the responsibility of that theme implementation to render #markup if + // required. Eventually #theme_wrappers will expect both #markup and + // #children to be a single string as #children. + if (isset($elements['#markup'])) { + $elements['#children'] = $elements['#markup'] . $elements['#children']; + } } // Add any JavaScript state information associated with the element. diff --git a/core/includes/theme.inc b/core/includes/theme.inc index a3f967a..35269f0 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -978,7 +978,10 @@ function theme($hook, $variables = array()) { if (!isset($candidate)) { watchdog('theme', 'Theme hook %hook not found.', array('%hook' => $hook), WATCHDOG_WARNING); } - return ''; + // There is no theme implementation for the hook passed. Return NULL so + // the function calling theme() can differentiate between a hook that + // exists and renders an empty string and a hook that is not implemented. + return NULL; } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTest.php b/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTest.php index 5054555..e3a9a9d 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTest.php @@ -182,7 +182,7 @@ function testRegistryRebuild() { // throws an exception. $this->rebuildContainer(); $this->container->get('module_handler')->loadAll(); - $this->assertIdentical(theme('theme_test_foo', array('foo' => 'b')), '', 'The theme registry does not contain theme_test_foo, because the module is disabled.'); + $this->assertIdentical(theme('theme_test_foo', array('foo' => 'b')), NULL, 'The theme registry does not contain theme_test_foo, because the module is disabled.'); module_enable(array('theme_test'), FALSE); // After enabling/disabling a module during a test, we need to rebuild the -- 1.7.11.1