summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2013-05-26 02:32:33 (GMT)
committerAlex Pott2013-05-26 02:32:33 (GMT)
commitf94711cd567793045b267e82ee97675ab52af664 (patch)
treee1820d1242a1fa0921ca4cbc9426e208b08ee24c
parent7961e03aebe72036294ad08d8cdcadd82881a992 (diff)
Issue #1987850 by oenie, vijaycs85, cosmicdreams, amateescu: Convert system_theme_disable() to a new style controller.
-rw-r--r--core/modules/system/lib/Drupal/system/Controller/ThemeController.php126
-rw-r--r--core/modules/system/system.admin.inc50
-rw-r--r--core/modules/system/system.module14
-rw-r--r--core/modules/system/system.routing.yml14
4 files changed, 140 insertions, 64 deletions
diff --git a/core/modules/system/lib/Drupal/system/Controller/ThemeController.php b/core/modules/system/lib/Drupal/system/Controller/ThemeController.php
new file mode 100644
index 0000000..61d931c
--- /dev/null
+++ b/core/modules/system/lib/Drupal/system/Controller/ThemeController.php
@@ -0,0 +1,126 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\system\Controller\ThemeController.
+ */
+
+namespace Drupal\system\Controller;
+
+use Drupal\Core\Config\Config;
+use Drupal\Core\Controller\ControllerInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+use Symfony\Component\HttpFoundation\RedirectResponse;
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
+
+/**
+ * Controller for theme handling.
+ */
+class ThemeController implements ControllerInterface {
+
+ /**
+ * The system.theme config object.
+ *
+ * @var \Drupal\Core\Config\Config
+ */
+ protected $config;
+
+ /**
+ * Constructs a ThemeController object.
+ *
+ * @param \Drupal\Core\Config\Config $config
+ * The config.
+ */
+ public function __construct(Config $config) {
+ $this->config = $config;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function create(ContainerInterface $container) {
+ return new static(
+ $container->get('config.factory')->get('system.theme')
+ );
+ }
+
+ /**
+ * Disables a theme.
+ *
+ * @param \Symfony\Component\HttpFoundation\Request $request
+ * A request object containing a theme name and a valid token.
+ *
+ * @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.
+ */
+ public function disable(Request $request) {
+ $theme = $request->get('theme');
+ $token = $request->get('token');
+
+ if (isset($theme) && isset($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])) {
+ // 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');
+ }
+ else {
+ theme_disable(array($theme));
+ drupal_set_message(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)));
+ }
+
+ throw new AccessDeniedHttpException();
+ }
+
+ /**
+ * Enables a theme.
+ *
+ * @param \Symfony\Component\HttpFoundation\Request $request
+ * A request object containing a theme name and a valid token.
+ *
+ * @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.
+ */
+ public function enable(Request $request) {
+ $theme = $request->get('theme');
+ $token = $request->get('token');
+
+ if (isset($theme) && isset($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])) {
+ theme_enable(array($theme));
+ drupal_set_message(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');
+ }
+
+ return new RedirectResponse(url('admin/appearance', array('absolute' => TRUE)));
+ }
+
+ throw new AccessDeniedHttpException();
+ }
+
+}
diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc
index 1566c80..a44060e 100644
--- a/core/modules/system/system.admin.inc
+++ b/core/modules/system/system.admin.inc
@@ -286,56 +286,6 @@ function system_themes_admin_form_submit($form, &$form_state) {
}
/**
- * Menu callback; Enables a theme.
- */
-function system_theme_enable() {
- if (isset($_REQUEST['theme']) && isset($_REQUEST['token']) && drupal_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])) {
- theme_enable(array($theme));
- drupal_set_message(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_goto('admin/appearance');
- }
- throw new AccessDeniedHttpException();
-}
-
-/**
- * Menu callback; Disables a theme.
- */
-function system_theme_disable() {
- if (isset($_REQUEST['theme']) && isset($_REQUEST['token']) && drupal_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])) {
- // Do not disable the default or admin theme.
- if ($theme === config('system.theme')->get('default') || $theme === config('system.theme')->get('admin')) {
- drupal_set_message(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'])));
- }
- }
- else {
- drupal_set_message(t('The %theme theme was not found.', array('%theme' => $theme)), 'error');
- }
- drupal_goto('admin/appearance');
- }
- throw new AccessDeniedHttpException();
-}
-
-/**
* Menu callback; Set the default theme.
*/
function system_theme_default() {
diff --git a/core/modules/system/system.module b/core/modules/system/system.module
index bf0977b..b6d37f0 100644
--- a/core/modules/system/system.module
+++ b/core/modules/system/system.module
@@ -703,20 +703,6 @@ function system_menu() {
'type' => MENU_DEFAULT_LOCAL_TASK,
'file' => 'system.admin.inc',
);
- $items['admin/appearance/enable'] = array(
- 'title' => 'Enable theme',
- 'page callback' => 'system_theme_enable',
- 'access arguments' => array('administer themes'),
- 'type' => MENU_CALLBACK,
- 'file' => 'system.admin.inc',
- );
- $items['admin/appearance/disable'] = array(
- 'title' => 'Disable theme',
- 'page callback' => 'system_theme_disable',
- 'access arguments' => array('administer themes'),
- 'type' => MENU_CALLBACK,
- 'file' => 'system.admin.inc',
- );
$items['admin/appearance/default'] = array(
'title' => 'Set default theme',
'page callback' => 'system_theme_default',
diff --git a/core/modules/system/system.routing.yml b/core/modules/system/system.routing.yml
index 9859d6a..1b4c9a9 100644
--- a/core/modules/system/system.routing.yml
+++ b/core/modules/system/system.routing.yml
@@ -87,3 +87,17 @@ date_format_localize_reset:
_form: '\Drupal\system\Form\DateFormatLocalizeResetForm'
requirements:
_permission: 'administer site configuration'
+
+system_theme_disable:
+ pattern: '/admin/appearance/disable'
+ defaults:
+ _controller: 'Drupal\system\Controller\ThemeController::disable'
+ requirements:
+ _permission: 'administer themes'
+
+system_theme_enable:
+ pattern: '/admin/appearance/enable'
+ defaults:
+ _controller: 'Drupal\system\Controller\ThemeController::enable'
+ requirements:
+ _permission: 'administer themes'