diff --git a/core/modules/system/lib/Drupal/system/Controller/SystemController.php b/core/modules/system/lib/Drupal/system/Controller/SystemController.php index fce6ba1..34a387e 100644 --- a/core/modules/system/lib/Drupal/system/Controller/SystemController.php +++ b/core/modules/system/lib/Drupal/system/Controller/SystemController.php @@ -321,12 +321,4 @@ public function themesPage() { return $build; } - /** - * @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 852d2b6..c397612 100644 --- a/core/modules/system/lib/Drupal/system/Controller/ThemeController.php +++ b/core/modules/system/lib/Drupal/system/Controller/ThemeController.php @@ -7,60 +7,60 @@ namespace Drupal\system\Controller; -use Drupal\Core\Config\Config; +use Drupal\Core\Controller\ControllerBase; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; +use Drupal\Core\Extension\ThemeHandlerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\HttpFoundation\RedirectResponse; +use Drupal\Core\Access\CsrfTokenGenerator; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; +use Symfony\Component\HttpFoundation\RedirectResponse; /** * Controller for theme handling. */ -class ThemeController implements ContainerInjectionInterface { - - /** - * The system.theme config object. - * - * @var \Drupal\Core\Config\Config - */ - protected $config; +class ThemeController extends ControllerBase implements ContainerInjectionInterface { /** - * Constructs a ThemeController object. - * - * @param \Drupal\Core\Config\Config $config - * The config. + * @var \Drupal\Core\Extension\ThemeHandlerInterface + * The theme handler. */ - public function __construct(Config $config) { - $this->config = $config; - } + protected $themeHandler; /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { return new static( - $container->get('config.factory')->get('system.theme') + $container->get('theme_handler') ); } /** + * Constructs a Theme Controller Object. + * + * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler + * The theme handler. + */ + 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'); - + $config = $this->config('system.theme'); if (isset($theme)) { // Get current list of themes. $themes = list_themes(); @@ -68,19 +68,16 @@ public function disable(Request $request) { // Check if the specified theme is one recognized by the system. if (!empty($themes[$theme])) { // Do not disable the default or admin theme. - if ($theme === $this->config->get('default') || $theme === $this->config->get('admin')) { - drupal_set_message(t('%theme is the default theme and cannot be disabled.', array('%theme' => $themes[$theme]->info['name'])), 'error'); + if ($theme === $config->get('default') || $theme === $config->get('admin')) { + 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->themeHandler->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'); - } - return new RedirectResponse(url('admin/appearance', array('absolute' => TRUE))); + return $this->redirect('system.themes_page'); } throw new AccessDeniedHttpException(); @@ -90,14 +87,13 @@ 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'); @@ -108,17 +104,80 @@ 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->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(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 defaultTheme(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->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. + 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 = $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 697f8c7..1f91617 100644 --- a/core/modules/system/system.admin.inc +++ b/core/modules/system/system.admin.inc @@ -9,58 +9,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 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(); -} - -/** * Recursively check compatibility. * * @param $incompatible @@ -218,6 +166,7 @@ function theme_admin_page($variables) { function theme_system_admin_index($variables) { $menu_items = $variables['menu_items']; + $stripe = 0; $container = array('left' => '', 'right' => ''); $flip = array('left' => 'right', 'right' => 'left'); $position = 'left'; @@ -422,12 +371,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 4d27aa6..a353b77 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'