Index: switchtheme.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/switchtheme/switchtheme.module,v retrieving revision 1.17 diff -u -p -r1.17 switchtheme.module --- switchtheme.module 10 Aug 2009 23:47:00 -0000 1.17 +++ switchtheme.module 11 Aug 2009 00:15:54 -0000 @@ -71,17 +71,18 @@ function switchtheme_init() { // If query parameter 'theme' is set, we always assign a new theme. if (isset($_REQUEST['theme'])) { - $form = array('values' => array('theme' => $_REQUEST['theme'])); - switchtheme_switch_form_submit('', $form); + $form_state = array('values' => array('theme' => $_REQUEST['theme'])); + switchtheme_switch_form_submit(array(), $form_state); } - // Other modules may already have set $custom_theme, so we actually switch - // the theme only if $custom_theme has not been set yet, or if we are on - // administrative pages and admin_theme has been set to "System default" - // ('0'). Also note that the chosen theme is stored in the global user - // object for authenticated users; that value is automatically used across - // sessions by Drupal core if the "select different theme" permission has - // been granted. - if (isset($_SESSION['custom_theme']) && (!isset($custom_theme) || $custom_theme === '0')) { + // We only switch the theme, if + // - no other module defined the global $custom_theme yet + // - the current page is an administrative page and the 'admin_theme' variable + // is set to the system default ('0') + // @see system_init() + // For users with the 'select different theme' permission, the chosen theme is + // stored in the {users}.theme; which is automatically used by Drupal core. + // @see init_theme() + if (isset($_SESSION['custom_theme']) && (empty($custom_theme) || $custom_theme === '0')) { $custom_theme = $_SESSION['custom_theme']; } @@ -191,14 +192,14 @@ function switchtheme_switch_form_submit( /** * Create an array of enabled themes to select from. - * - * @todo Probably should come back here and cache the theme list. */ function switchtheme_options() { - $themes = list_themes(); - foreach ($themes as $name => $attr) { - if ($attr->status) { - $options[$attr->name] = $attr->name; + // Ensure the database is ready. + // @see init_theme() + drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE); + foreach (list_themes() as $name => $info) { + if ($info->status) { + $options[$name] = $info->name; } } return $options;