diff --git c/core/modules/system/lib/Drupal/system/Controller/ThemeController.php w/core/modules/system/lib/Drupal/system/Controller/ThemeController.php index 39749e8..b498713 100644 --- c/core/modules/system/lib/Drupal/system/Controller/ThemeController.php +++ w/core/modules/system/lib/Drupal/system/Controller/ThemeController.php @@ -7,8 +7,9 @@ namespace Drupal\system\Controller; -use Drupal\Core\Config\Config; use Drupal\Core\Controller\ControllerBase; +use Drupal\Core\DependencyInjection\ContainerInjectionInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\Access\CsrfTokenGenerator; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; @@ -17,9 +18,34 @@ /** * Controller for theme handling. */ -class ThemeController extends ControllerBase { +class ThemeController extends ControllerBase implements ContainerInjectionInterface { /** + * Token generator service. + * + * @var \Drupal\Core\Access\CsrfTokenGenerator + */ + protected $tokenGenerator; + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('csrf_token') + ); + } + + /** + * Constructs a Theme Controller Object. + * + * @param \Drupal\Core\Access\CsrfTokenGenerator $token_generator + * Token Generator Service. + */ + public function __construct(CsrfTokenGenerator $token_generator) { + $this->tokenGenerator = $token_generator; + } + /** * Disables a theme. * * @param \Symfony\Component\HttpFoundation\Request $request @@ -37,7 +63,7 @@ public function disable(Request $request) { $token = $request->get('token'); $config = $this->config('system.theme'); - if (isset($theme) && isset($token) && $this->getTokenGenerator()->validate($token, 'system-theme-operation-link')) { + if (isset($theme) && isset($token) && $this->tokenGenerator->validate($token, 'system-theme-operation-link')) { // Get current list of themes. $themes = list_themes(); @@ -80,7 +106,7 @@ public function enable(Request $request) { $theme = $request->get('theme'); $token = $request->get('token'); - if (isset($theme) && isset($token) && $this->getTokenGenerator()->validate($token, 'system-theme-operation-link')) { + if (isset($theme) && isset($token) && $this->tokenGenerator->validate($token, 'system-theme-operation-link')) { // Get current list of themes. $themes = list_themes(TRUE); @@ -118,7 +144,7 @@ public function defaultTheme(Request $request) { $theme = $request->query->get('theme'); $token = $request->query->get('token'); - if (isset($theme) && isset($token) && $this->getTokenGenerator()->validate($token, 'system-theme-operation-link')) { + if (isset($theme) && isset($token) && $this->tokenGenerator->validate($token, 'system-theme-operation-link')) { // Get current list of themes. $themes = list_themes(); @@ -162,17 +188,4 @@ public function defaultTheme(Request $request) { throw new AccessDeniedHttpException(); } - /** - * Gets Token Generator Service. - * - * @return \Drupal\Core\Access\CsrfTokenGenerator - **/ - public function getTokenGenerator() - { - if (empty($this->tokenGenerator)) { - $this->tokenGenerator = $this->container->get('csrf_token'); - } - return $this->tokenGenerator; - } - } diff --git c/core/modules/system/system.admin.inc w/core/modules/system/system.admin.inc index 9db20be..8245cb5 100644 --- c/core/modules/system/system.admin.inc +++ w/core/modules/system/system.admin.inc @@ -176,57 +176,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'); - $token = $request->get('token'); - if (!empty($theme) && !empty($token) && drupal_valid_token($token, 'system-theme-operation-link')) { - // 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. - 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 = 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