From a49f52609af28cb14a05ce664bce654d367514ce Mon Sep 17 00:00:00 2001
From: David Meister <thedavidmeister@gmail.com>
Date: Sun, 9 Jun 2013 17:50:58 +1000
Subject: [PATCH] 2012812-16

---
 core/includes/common.inc | 24 +++++++++++++-----------
 core/includes/theme.inc  |  5 ++++-
 2 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/core/includes/common.inc b/core/includes/common.inc
index 00decfa..5359d09 100644
--- a/core/includes/common.inc
+++ b/core/includes/common.inc
@@ -4797,26 +4797,28 @@ function drupal_render(&$elements) {
   // Get the children of the element, sorted by weight.
   $children = element_children($elements, TRUE);
 
-  // Initialize this element's #children, unless a #pre_render callback already
-  // preset #children.
-  if (!isset($elements['#children'])) {
-    $elements['#children'] = '';
-  }
-  // 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.
-  if (isset($elements['#theme']) && !isset($elements['#render_children'])) {
+  // Initialize #children unless it was set by #pre_render.
+  $elements['#children'] = isset($elements['#children']) ? $elements['#children'] : NULL;
+
+  // Call the element's #theme function if it is set unless a #pre_render
+  // callback already preset #children. 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.
+  if (!isset($elements['#children']) && 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 (!isset($elements['#children'])) {
     foreach ($children as $key) {
       $elements['#children'] .= drupal_render($elements[$key]);
     }
   }
+  if (empty($elements['#children'])) {
+    $elements['#children'] = '';
+  }
+
   // 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
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;
     }
   }
 
-- 
1.7.11.1

