diff --git a/core/modules/system/lib/Drupal/system/Controller/SystemController.php b/core/modules/system/lib/Drupal/system/Controller/SystemController.php index 5f55d6e..01a9b29 100644 --- a/core/modules/system/lib/Drupal/system/Controller/SystemController.php +++ b/core/modules/system/lib/Drupal/system/Controller/SystemController.php @@ -322,14 +322,6 @@ public function themesPage() { } /** - * @todo Remove system_theme_default(). - */ - public function themeSetDefault() { - module_load_include('admin.inc', 'system'); - return system_theme_default(); - } - - /** * #post_render_cache callback; sets the "active" class on relevant links. * * This is a PHP implementation of the drupal.active-link JavaScript library. diff --git a/core/modules/system/lib/Drupal/system/Controller/ThemeController.php b/core/modules/system/lib/Drupal/system/Controller/ThemeController.php index ece04d5..2337a33 100644 --- a/core/modules/system/lib/Drupal/system/Controller/ThemeController.php +++ b/core/modules/system/lib/Drupal/system/Controller/ThemeController.php @@ -42,18 +42,18 @@ public function disable(Request $request) { if (!empty($themes[$theme])) { // Do not disable the default or admin theme. if ($theme === $config->get('default') || $theme === $config->get('admin')) { - drupal_set_message(t('%theme is the default theme and cannot be disabled.', array('%theme' => $themes[$theme]->info['name'])), 'error'); + drupal_set_message($this->t('%theme is the default theme and cannot be disabled.', array('%theme' => $themes[$theme]->info['name'])), 'error'); } else { - theme_disable(array($theme)); - drupal_set_message(t('The %theme theme has been disabled.', array('%theme' => $themes[$theme]->info['name']))); + $this->get('theme_handler')->disable(array($theme)); + drupal_set_message($this->t('The %theme theme has been disabled.', array('%theme' => $themes[$theme]->info['name']))); } } else { - drupal_set_message(t('The %theme theme was not found.', array('%theme' => $theme)), 'error'); + drupal_set_message($this->t('The %theme theme was not found.', array('%theme' => $theme)), 'error'); } - return new RedirectResponse(url('admin/appearance', array('absolute' => TRUE))); + return $this->redirect('system.themes_page'); } throw new AccessDeniedHttpException(); @@ -81,17 +81,79 @@ public function enable(Request $request) { // Check if the specified theme is one recognized by the system. if (!empty($themes[$theme])) { - theme_enable(array($theme)); - drupal_set_message(t('The %theme theme has been enabled.', array('%theme' => $themes[$theme]->info['name']))); + $this->get('theme_handler')->enable(array($theme)); + drupal_set_message($this->t('The %theme theme has been enabled.', array('%theme' => $themes[$theme]->info['name']))); } else { - drupal_set_message(t('The %theme theme was not found.', array('%theme' => $theme)), 'error'); + drupal_set_message($this->t('The %theme theme was not found.', array('%theme' => $theme)), 'error'); } - return new RedirectResponse(url('admin/appearance', array('absolute' => TRUE))); + return $this->redirect('system.themes_page'); } throw new AccessDeniedHttpException(); } + /** + * Set the default theme. + * + * @param \Symfony\Component\HttpFoundation\Request $request + * A request object containing a theme name. + * + * @return \Symfony\Component\HttpFoundation\RedirectResponse + * Redirects back to the appearance admin page. + * + * @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException + * Throws access denied when no theme is set in the request. + */ + public function setDefaultTheme(Request $request) { + $config = $this->config('system.theme'); + $theme = $request->query->get('theme'); + + if (isset($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)) { + $this->get('theme_handler')->enable(array($theme)); + } + + // Set the default theme. + $config->set('default', $theme)->save(); + + // 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 saving the configuration before the + // theme_enable() could result in a race condition where the theme is + // default but not enabled. + \Drupal::service('router.builder')->setRebuildNeeded(); + + // 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('admin'); + if ($admin_theme != 0 && $admin_theme != $theme) { + drupal_set_message($this->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($this->t('%theme is now the default theme.', array('%theme' => $themes[$theme]->info['name']))); + } + } + else { + drupal_set_message($this->t('The %theme theme was not found.', array('%theme' => $theme)), 'error'); + } + + return $this->redirect('system.themes_page'); + + } + throw new AccessDeniedHttpException(); + } + } diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc index 4a6005d..e2f1a49 100644 --- a/core/modules/system/system.admin.inc +++ b/core/modules/system/system.admin.inc @@ -10,56 +10,6 @@ use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; /** - * Menu callback; Set the default theme. - */ -function system_theme_default() { - $request = \Drupal::request(); - $theme = $request->get('theme'); - if (!empty($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. - \Drupal::config('system.theme') - ->set('default', $theme) - ->save(); - - // 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 saving the configuration before the theme_enable() - // could result in a race condition where the theme is default but not - // enabled. - \Drupal::service('router.builder')->setRebuildNeeded(); - - // 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 = \Drupal::config('system.theme')->get('admin'); - 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'); - } - return new RedirectResponse(url('admin/appearance', array('absolute' => TRUE))); - } - throw new AccessDeniedHttpException(); -} - -/** * Recursively check compatibility. * * @param $incompatible @@ -399,12 +349,7 @@ function theme_system_modules_details($variables) { $rows[] = $row; } - $table = array( - '#theme' => 'table', - '#header' => $form['#header'], - '#rows' => $rows, - ); - return drupal_render($table); + return theme('table', array('header' => $form['#header'], 'rows' => $rows)); } /** diff --git a/core/modules/system/system.routing.yml b/core/modules/system/system.routing.yml index 9be827e..2269803 100644 --- a/core/modules/system/system.routing.yml +++ b/core/modules/system/system.routing.yml @@ -320,7 +320,7 @@ system.theme_set_default: path: '/admin/appearance/default' defaults: _title: 'Set default theme' - _content: '\Drupal\system\Controller\SystemController::themeSetDefault' + _content: '\Drupal\system\Controller\ThemeController::setDefaultTheme' requirements: _permission: 'administer themes' _csrf_token: 'TRUE'