1 system.admin.inc system_theme_default()

Menu callback; Set the default theme.


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


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)) {
      // 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.

      // 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 the admin theme is set to a different theme than the one the user
      // has just switched to, show an info message to explain why.
      if ($admin_theme && $admin_theme != $theme) {
        backdrop_set_message(t('%theme is now the default theme for all non-administrative pages.', array('%theme' => $themes[$theme]->info['name'])));
        backdrop_set_message(t('The <a href="@admin_theme_setting">administration theme</a> is still set to the %admin_theme theme.', array(
          '%admin_theme' => $themes[$admin_theme]->info['name'],
          '@admin_theme_setting' => url('admin/appearance', $options = array('fragment' => 'system-themes-admin-form')),
        )), 'info');
      else {
        backdrop_set_message(t('%theme is now the default theme.', array('%theme' => $themes[$theme]->info['name'])));

      // Clear caches after changing the theme.
      if (user_access('flush caches')) {
        backdrop_set_message(t('All caches have been cleared.'));

    else {
      backdrop_set_message(t('The %theme theme was not found.', array('%theme' => $theme)), 'error');