1 system.admin.inc system_theme_default()

Menu callback; Set the default theme.

File

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

Code

function system_theme_default() {
  if (isset($_REQUEST['theme']) && isset($_REQUEST['token']) && backdrop_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.
      config_set('system.core', 'theme_default', $theme);

      // Rebuild the menu. This duplicates the menu_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 config_set() before the theme_enable() could result
      // in a race condition where the theme is default but not enabled.
      menu_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 = config_get('system.core', 'admin_theme');
      if ($admin_theme && $admin_theme != $theme) {
        backdrop_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 {
        backdrop_set_message(t('%theme is now the default theme.', array('%theme' => $themes[$theme]->info['name'])));
      }
    }
    else {
      backdrop_set_message(t('The %theme theme was not found.', array('%theme' => $theme)), 'error');
    }
    backdrop_goto('admin/appearance');
  }
  return MENU_ACCESS_DENIED;
}