diff --git a/core/modules/system/lib/Drupal/system/Controller/SystemController.php b/core/modules/system/lib/Drupal/system/Controller/SystemController.php index 6145a11..10b44fa 100644 --- a/core/modules/system/lib/Drupal/system/Controller/SystemController.php +++ b/core/modules/system/lib/Drupal/system/Controller/SystemController.php @@ -153,12 +153,4 @@ public function themesPage() { return system_themes_page(); } - /** - * @todo Remove system_theme_default(). - */ - public function themeSetDefault() { - module_load_include('admin.inc', 'system'); - return system_theme_default(); - } - } diff --git a/core/modules/system/lib/Drupal/system/Controller/ThemeController.php b/core/modules/system/lib/Drupal/system/Controller/ThemeController.php index 353317f..c397612 100644 --- a/core/modules/system/lib/Drupal/system/Controller/ThemeController.php +++ b/core/modules/system/lib/Drupal/system/Controller/ThemeController.php @@ -9,6 +9,7 @@ use Drupal\Core\Controller\ControllerBase; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; +use Drupal\Core\Extension\ThemeHandlerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\Access\CsrfTokenGenerator; use Symfony\Component\HttpFoundation\Request; @@ -21,48 +22,46 @@ class ThemeController extends ControllerBase implements ContainerInjectionInterface { /** - * Token generator service. - * - * @var \Drupal\Core\Access\CsrfTokenGenerator + * @var \Drupal\Core\Extension\ThemeHandlerInterface + * The theme handler. */ - protected $tokenGenerator; + protected $themeHandler; /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { return new static( - $container->get('csrf_token') + $container->get('theme_handler') ); } /** * Constructs a Theme Controller Object. * - * @param \Drupal\Core\Access\CsrfTokenGenerator $token_generator - * Token Generator Service. + * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler + * The theme handler. */ - public function __construct(CsrfTokenGenerator $token_generator) { - $this->tokenGenerator = $token_generator; + public function __construct(ThemeHandlerInterface $theme_handler) { + $this->themeHandler = $theme_handler; } + /** * Disables a theme. * * @param \Symfony\Component\HttpFoundation\Request $request - * A request object containing a theme name and a valid token. + * 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 or token is set in the request or when - * the token is invalid. + * Throws access denied when no theme set in the request */ public function disable(Request $request) { $theme = $request->get('theme'); - $token = $request->get('token'); $config = $this->config('system.theme'); - if (isset($theme) && isset($token) && $this->tokenGenerator->validate($token, 'system-theme-operation-link')) { + if (isset($theme)) { // Get current list of themes. $themes = list_themes(); @@ -73,12 +72,12 @@ public function disable(Request $request) { 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)); + $this->themeHandler->disable(array($theme)); drupal_set_message($this->t('The %theme theme has been disabled.', array('%theme' => $themes[$theme]->info['name']))); } } - return new RedirectResponse($this->urlGenerator()->generateFromPath('admin/appearance', array('absolute' => TRUE))); + return $this->redirect('system.themes_page'); } throw new AccessDeniedHttpException(); @@ -88,35 +87,32 @@ public function disable(Request $request) { * Enables a theme. * * @param \Symfony\Component\HttpFoundation\Request $request - * A request object containing a theme name and a valid token. + * 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 or token is set in the request or when - * the token is invalid. + * Throws access denied when no theme is set in the request. */ public function enable(Request $request) { $theme = $request->get('theme'); - $token = $request->get('token'); - $config = $this->config('system.theme'); - if (isset($theme) && isset($token) && $this->tokenGenerator->validate($token, 'system-theme-operation-link')) { + if (isset($theme)) { // Get current list of themes. $themes = list_themes(TRUE); // Check if the specified theme is one recognized by the system. if (!empty($themes[$theme])) { - theme_enable(array($theme)); + $this->themeHandler->enable(array($theme)); drupal_set_message($this->t('The %theme theme has been enabled.', array('%theme' => $themes[$theme]->info['name']))); } else { drupal_set_message($this->t('The %theme theme was not found.', array('%theme' => $theme)), 'error'); } - // @todo switch to $this->redirect when admin/appearance converted. - return new RedirectResponse($this->urlGenerator()->generateFromPath('admin/appearance', array('absolute' => TRUE))); + return $this->redirect('system.themes_page'); + } throw new AccessDeniedHttpException(); @@ -126,21 +122,19 @@ public function enable(Request $request) { * Set the default theme. * * @param \Symfony\Component\HttpFoundation\Request $request - * A request object containing a theme name and a valid token. + * 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 or token is set in the request or when - * the token is invalid. + * Throws access denied when no theme is set in the request. */ public function defaultTheme(Request $request) { $config = $this->config('system.theme'); - $theme = $request->query->get('theme'); - $token = $request->query->get('token'); - if (isset($theme) && isset($token) && $this->tokenGenerator->validate($token, 'system-theme-operation-link')) { + + if (isset($theme)) { // Get current list of themes. $themes = list_themes(); @@ -148,22 +142,23 @@ public function defaultTheme(Request $request) { if (!empty($themes[$theme])) { // Enable the theme if it is currently disabled. if (empty($themes[$theme]->status)) { - theme_enable(array($theme)); + $this->themeHandler->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 doing the variable_set() before the theme_enable() - // could result in a race condition where the theme is default but not - // enabled. + // 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. + // 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( @@ -178,8 +173,9 @@ public function defaultTheme(Request $request) { else { drupal_set_message($this->t('The %theme theme was not found.', array('%theme' => $theme)), 'error'); } - // @todo switch to $this->redirect when admin/appearance converted. - return new RedirectResponse($this->urlGenerator()->generateFromPath('admin/appearance', array('absolute' => TRUE))); + + 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 726d965..241ca20 100644 --- a/core/modules/system/system.admin.inc +++ b/core/modules/system/system.admin.inc @@ -185,59 +185,6 @@ function system_themes_admin_form_submit($form, &$form_state) { } /** - * 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 doing the variable_set() before the theme_enable() - // could result in a race condition where the theme is default but not - // enabled. - \Drupal::service('router.builder')->rebuild(); - menu_router_rebuild(); - \Drupal::cache('cache')->deleteTags(array('local_task' => 1)); - - // 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(); - Drupal::config('system.theme')->set('admin', $form_state['values']['admin_theme'])->save(); -} - -/** * Recursively check compatibility. * * @param $incompatible diff --git a/core/modules/system/system.routing.yml b/core/modules/system/system.routing.yml index 25108ce..a770d97 100644 --- a/core/modules/system/system.routing.yml +++ b/core/modules/system/system.routing.yml @@ -319,7 +319,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::defaultTheme' requirements: _permission: 'administer themes' _csrf_token: 'TRUE'