diff --git a/core/lib/Drupal/Core/Theme/ThemeManager.php b/core/lib/Drupal/Core/Theme/ThemeManager.php
index 6850fcb..bb53bd8 100644
--- a/core/lib/Drupal/Core/Theme/ThemeManager.php
+++ b/core/lib/Drupal/Core/Theme/ThemeManager.php
@@ -200,27 +200,32 @@ protected function theme($hook, $variables = array()) {
     if (isset($variables['#theme']) || isset($variables['#theme_wrappers'])) {
       $element = $variables;
       $variables = array();
-      if (isset($info['variables'])) {
-        foreach (array_keys($info['variables']) as $name) {
-          if (isset($element["#$name"]) || array_key_exists("#$name", $element)) {
-            $variables[$name] = $element["#$name"];
-          }
+
+      // Setup the variables from the render array.
+      foreach ($element as $key => $value) {
+        if ($key[0] == '#') {
+          $variables[ltrim($key, '#')] = $value;
         }
       }
-      else {
+
+      // Add the entire element as the render element with all it's children.
+      if (!empty($info['render element'])) {
         $variables[$info['render element']] = $element;
         // Give a hint to render engines to prevent infinite recursion.
         $variables[$info['render element']]['#render_children'] = TRUE;
       }
     }
 
-    // Merge in argument defaults.
+    // Add the variable defaults.
     if (!empty($info['variables'])) {
       $variables += $info['variables'];
     }
-    elseif (!empty($info['render element'])) {
-      $variables += array($info['render element'] => array());
+
+    // Add render element default key.
+    if (!empty($info['render element'])) {
+      $variables += [$info['render element'] => []];
     }
+
     // Supply original caller info.
     $variables += array(
       'theme_hook_original' => $original_hook,
