function system_theme_default

Menu callback; Set the default theme.

1 string reference to 'system_theme_default'
system_menu in drupal/core/modules/system/system.module
Implements hook_menu().

File

drupal/core/modules/system/system.admin.inc, line 331
Admin page callbacks for the system module.

Code

function system_theme_default() {
  if (isset($_REQUEST['theme']) && isset($_REQUEST['token']) && drupal_valid_token($_REQUEST['token'], 'system-theme-operation-link')) {
    $theme = $_REQUEST['theme'];

    // Get current list of themes.
    $themes = list_themes();

    // Check if the specified theme is one recognized by the system.
    if (!empty($themes[$theme])) {

      // Enable the theme if it is currently disabled.
      if (empty($themes[$theme]->status)) {
        theme_enable(array(
          $theme,
        ));
      }

      // Set the default theme.
      variable_set('theme_default', $theme);

      // Rebuild the menu. This duplicates the menu_router_rebuild() in
      // theme_enable(). However, modules must know the current default theme in
      // order to use this information in hook_menu() or hook_menu_alter()
      // implementations, and doing the variable_set() before the theme_enable()
      // could result in a race condition where the theme is default but not
      // enabled.
      menu_router_rebuild();

      // The status message depends on whether an admin theme is currently in use:
      // a value of 0 means the admin theme is set to be the default theme.
      $admin_theme = variable_get('admin_theme', 0);
      if ($admin_theme != 0 && $admin_theme != $theme) {
        drupal_set_message(t('Please note that the administration theme is still set to the %admin_theme theme; consequently, the theme on this page remains unchanged. All non-administrative sections of the site, however, will show the selected %selected_theme theme by default.', array(
          '%admin_theme' => $themes[$admin_theme]->info['name'],
          '%selected_theme' => $themes[$theme]->info['name'],
        )));
      }
      else {
        drupal_set_message(t('%theme is now the default theme.', array(
          '%theme' => $themes[$theme]->info['name'],
        )));
      }
    }
    else {
      drupal_set_message(t('The %theme theme was not found.', array(
        '%theme' => $theme,
      )), 'error');
    }
    drupal_goto('admin/appearance');
  }
  throw new AccessDeniedHttpException();
}