From 679372502bac82b614814312e557979b0151014a Mon Sep 17 00:00:00 2001
From: Dries Buytaert <dries@buytaert.net>
Date: Tue, 14 Sep 2010 21:42:05 +0000
Subject: [PATCH] - Patch #910572 by sun, David_Rothstein: command line
 installations are broken (programmatic form submissions don't need a theme?).

---
 includes/form.inc         | 34 +++++-----------------------------
 includes/install.core.inc | 12 ++++++------
 includes/theme.inc        |  6 +++++-
 3 files changed, 16 insertions(+), 36 deletions(-)

diff --git a/includes/form.inc b/includes/form.inc
index 0c50e190b1da..59ed6517af49 100644
--- a/includes/form.inc
+++ b/includes/form.inc
@@ -929,38 +929,14 @@ function drupal_prepare_form($form_id, &$form, &$form_state) {
     }
   }
 
-  // Check theme functions for this form.
+  // If no #theme has been set, automatically apply theme suggestions.
   // theme_form() itself is in #theme_wrappers and not #theme. Therefore, the
   // #theme function only has to care for rendering the inner form elements,
   // not the form itself.
-  drupal_theme_initialize();
-  $registry = theme_get_registry();
-  // If #theme has been set, check whether the theme function(s) exist, or
-  // remove the suggestion(s), so drupal_render() renders the children.
-  if (isset($form['#theme'])) {
-    if (is_array($form['#theme'])) {
-      foreach ($form['#theme'] as $key => $suggestion) {
-        if (!isset($registry[$suggestion])) {
-          unset($form['#theme'][$key]);
-        }
-      }
-      if (empty($form['#theme'])) {
-        unset($form['#theme']);
-      }
-    }
-    else {
-      if (!isset($registry[$form['#theme']])) {
-        unset($form['#theme']);
-      }
-    }
-  }
-  // Only try to auto-suggest theme functions, if #theme has not been set.
-  else {
-    if (isset($registry[$form_id])) {
-      $form['#theme'] = $form_id;
-    }
-    elseif (isset($form_state['build_info']['base_form_id']) && isset($registry[$form_state['build_info']['base_form_id']])) {
-      $form['#theme'] = $form_state['build_info']['base_form_id'];
+  if (!isset($form['#theme'])) {
+    $form['#theme'] = array($form_id);
+    if (isset($form_state['build_info']['base_form_id'])) {
+      $form['#theme'][] = $form_state['build_info']['base_form_id'];
     }
   }
 
diff --git a/includes/install.core.inc b/includes/install.core.inc
index a334f7bb3d6e..906a48e43558 100644
--- a/includes/install.core.inc
+++ b/includes/install.core.inc
@@ -275,12 +275,12 @@ function install_begin_request(&$install_state) {
   require_once DRUPAL_ROOT . '/includes/cache-install.inc';
   $conf['cache_default_class'] = 'DrupalFakeCache';
 
-  // Prepare for themed output, if necessary. We need to run this at the
-  // beginning of the page request to avoid a different theme accidentally
-  // getting set.
-  if ($install_state['interactive']) {
-    drupal_maintenance_theme();
-  }
+  // Prepare for themed output. We need to run this at the beginning of the
+  // page request to avoid a different theme accidentally getting set. (We also
+  // need to run it even in the case of command-line installations, to prevent
+  // any code in the installer that happens to initialize the theme system from
+  // accessing the database before it is set up yet.)
+  drupal_maintenance_theme();
 
   // Check existing settings.php.
   $install_state['settings_verified'] = install_verify_settings();
diff --git a/includes/theme.inc b/includes/theme.inc
index 5a7b591f871e..87c8dba5094c 100644
--- a/includes/theme.inc
+++ b/includes/theme.inc
@@ -768,7 +768,11 @@ function theme($hook, $variables = array()) {
       }
     }
     if (!isset($hooks[$hook])) {
-      watchdog('theme', 'Theme key "@key" not found.', array('@key' => $hook), WATCHDOG_WARNING);
+      // Only log a message when not trying theme suggestions ($hook being an
+      // array).
+      if (!isset($candidate)) {
+        watchdog('theme', 'Theme key "@key" not found.', array('@key' => $hook), WATCHDOG_WARNING);
+      }
       return '';
     }
   }
-- 
GitLab