diff --git a/core/modules/system/lib/Drupal/system/Controller/ThemeController.php b/core/modules/system/lib/Drupal/system/Controller/ThemeController.php index 61d931c..3017b6e 100644 --- a/core/modules/system/lib/Drupal/system/Controller/ThemeController.php +++ b/core/modules/system/lib/Drupal/system/Controller/ThemeController.php @@ -123,4 +123,139 @@ public function enable(Request $request) { throw new AccessDeniedHttpException(); } + + /** + * Displays a listing of all themes. + */ + public function getAllThemes() { + // Get current list of themes. + $themes = system_rebuild_theme_data(); + uasort($themes, 'system_sort_modules_by_info_name'); + + $theme_default = config('system.theme')->get('default'); + $theme_groups = array(); + $admin_theme = config('system.theme')->get('admin'); + + foreach ($themes as &$theme) { + if (!empty($theme->info['hidden'])) { + continue; + } + $theme->is_default = ($theme->name == $theme_default); + + // Identify theme screenshot. + $theme->screenshot = NULL; + // Create a list which includes the current theme and all its base themes. + if (isset($themes[$theme->name]->base_themes)) { + $theme_keys = array_keys($themes[$theme->name]->base_themes); + $theme_keys[] = $theme->name; + } + else { + $theme_keys = array($theme->name); + } + // Look for a screenshot in the current theme or in its closest ancestor. + foreach (array_reverse($theme_keys) as $theme_key) { + if (isset($themes[$theme_key]) && file_exists($themes[$theme_key]->info['screenshot'])) { + $theme->screenshot = array( + 'uri' => $themes[$theme_key]->info['screenshot'], + 'alt' => t('Screenshot for !theme theme', array('!theme' => $theme->info['name'])), + 'title' => t('Screenshot for !theme theme', array('!theme' => $theme->info['name'])), + 'attributes' => array('class' => array('screenshot')), + ); + break; + } + } + + if (empty($theme->status)) { + // Ensure this theme is compatible with this version of core. + // Require the 'content' region to make sure the main page + // content has a common place in all themes. + $theme->incompatible_core = !isset($theme->info['core']) || ($theme->info['core'] != DRUPAL_CORE_COMPATIBILITY) || (!isset($theme->info['regions']['content'])); + $theme->incompatible_php = version_compare(phpversion(), $theme->info['php']) < 0; + // Confirmed that the base theme is available. + $theme->incompatible_base = (isset($theme->info['base theme']) && !isset($themes[$theme->info['base theme']])); + // Confirm that the theme engine is available. + $theme->incompatible_engine = (isset($theme->info['engine']) && !isset($theme->owner)); + } + $query['token'] = drupal_get_token('system-theme-operation-link'); + $theme->operations = array(); + if (!empty($theme->status) || !$theme->incompatible_core && !$theme->incompatible_php && !$theme->incompatible_base && !$theme->incompatible_engine) { + // Create the operations links. + $query['theme'] = $theme->name; + if (drupal_theme_access($theme)) { + $theme->operations[] = array( + 'title' => t('Settings'), + 'href' => 'admin/appearance/settings/' . $theme->name, + 'attributes' => array('title' => t('Settings for !theme theme', array('!theme' => $theme->info['name']))), + ); + } + if (!empty($theme->status)) { + if (!$theme->is_default) { + if ($theme->name != $admin_theme) { + $theme->operations[] = array( + 'title' => t('Disable'), + 'href' => 'admin/appearance/disable', + 'query' => $query, + 'attributes' => array('title' => t('Disable !theme theme', array('!theme' => $theme->info['name']))), + ); + } + $theme->operations[] = array( + 'title' => t('Set default'), + 'href' => 'admin/appearance/default', + 'query' => $query, + 'attributes' => array('title' => t('Set !theme as default theme', array('!theme' => $theme->info['name']))), + ); + } + $admin_theme_options[$theme->name] = $theme->info['name']; + } + else { + $theme->operations[] = array( + 'title' => t('Enable'), + 'href' => 'admin/appearance/enable', + 'query' => $query, + 'attributes' => array('title' => t('Enable !theme theme', array('!theme' => $theme->info['name']))), + ); + $theme->operations[] = array( + 'title' => t('Enable and set default'), + 'href' => 'admin/appearance/default', + 'query' => $query, + 'attributes' => array('title' => t('Enable !theme as default theme', array('!theme' => $theme->info['name']))), + ); + } + } + + // Add notes to default and administration theme. + $theme->notes = array(); + $theme->classes = array(); + if ($theme->is_default) { + $theme->classes[] = 'theme-default'; + $theme->notes[] = t('default theme'); + } + if ($theme->name == $admin_theme || ($theme->is_default && $admin_theme == '0')) { + $theme->classes[] = 'theme-admin'; + $theme->notes[] = t('admin theme'); + } + + // Sort enabled and disabled themes into their own groups. + $theme_groups[$theme->status ? 'enabled' : 'disabled'][] = $theme; + } + + // There are two possible theme groups. + $theme_group_titles = array( + 'enabled' => format_plural(count($theme_groups['enabled']), 'Enabled theme', 'Enabled themes'), + ); + if (!empty($theme_groups['disabled'])) { + $theme_group_titles['disabled'] = format_plural(count($theme_groups['disabled']), 'Disabled theme', 'Disabled themes'); + } + + uasort($theme_groups['enabled'], 'system_sort_themes'); + drupal_alter('system_themes_page', $theme_groups); + + $admin_form = drupal_get_form('system_themes_admin_form', $admin_theme_options); + $system_themes_page = array( + '#theme' => 'system_themes_page', + '#theme_groups' => $theme_groups, + '#theme_group_titles' => $theme_group_titles, + ); + return drupal_render($system_themes_page). drupal_render($admin_form); + } } diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc index 6177dfd..881255d 100644 --- a/core/modules/system/system.admin.inc +++ b/core/modules/system/system.admin.inc @@ -122,171 +122,6 @@ function system_admin_index() { } /** - * Menu callback; displays a listing of all themes. - */ -function system_themes_page() { - // Get current list of themes. - $themes = system_rebuild_theme_data(); - uasort($themes, 'system_sort_modules_by_info_name'); - - $theme_default = config('system.theme')->get('default'); - $theme_groups = array(); - $admin_theme = config('system.theme')->get('admin'); - - foreach ($themes as &$theme) { - if (!empty($theme->info['hidden'])) { - continue; - } - $theme->is_default = ($theme->name == $theme_default); - - // Identify theme screenshot. - $theme->screenshot = NULL; - // Create a list which includes the current theme and all its base themes. - if (isset($themes[$theme->name]->base_themes)) { - $theme_keys = array_keys($themes[$theme->name]->base_themes); - $theme_keys[] = $theme->name; - } - else { - $theme_keys = array($theme->name); - } - // Look for a screenshot in the current theme or in its closest ancestor. - foreach (array_reverse($theme_keys) as $theme_key) { - if (isset($themes[$theme_key]) && file_exists($themes[$theme_key]->info['screenshot'])) { - $theme->screenshot = array( - 'uri' => $themes[$theme_key]->info['screenshot'], - 'alt' => t('Screenshot for !theme theme', array('!theme' => $theme->info['name'])), - 'title' => t('Screenshot for !theme theme', array('!theme' => $theme->info['name'])), - 'attributes' => array('class' => array('screenshot')), - ); - break; - } - } - - if (empty($theme->status)) { - // Ensure this theme is compatible with this version of core. - // Require the 'content' region to make sure the main page - // content has a common place in all themes. - $theme->incompatible_core = !isset($theme->info['core']) || ($theme->info['core'] != DRUPAL_CORE_COMPATIBILITY) || (!isset($theme->info['regions']['content'])); - $theme->incompatible_php = version_compare(phpversion(), $theme->info['php']) < 0; - // Confirmed that the base theme is available. - $theme->incompatible_base = (isset($theme->info['base theme']) && !isset($themes[$theme->info['base theme']])); - // Confirm that the theme engine is available. - $theme->incompatible_engine = (isset($theme->info['engine']) && !isset($theme->owner)); - } - $query['token'] = drupal_get_token('system-theme-operation-link'); - $theme->operations = array(); - if (!empty($theme->status) || !$theme->incompatible_core && !$theme->incompatible_php && !$theme->incompatible_base && !$theme->incompatible_engine) { - // Create the operations links. - $query['theme'] = $theme->name; - if (drupal_theme_access($theme)) { - $theme->operations[] = array( - 'title' => t('Settings'), - 'href' => 'admin/appearance/settings/' . $theme->name, - 'attributes' => array('title' => t('Settings for !theme theme', array('!theme' => $theme->info['name']))), - ); - } - if (!empty($theme->status)) { - if (!$theme->is_default) { - if ($theme->name != $admin_theme) { - $theme->operations[] = array( - 'title' => t('Disable'), - 'href' => 'admin/appearance/disable', - 'query' => $query, - 'attributes' => array('title' => t('Disable !theme theme', array('!theme' => $theme->info['name']))), - ); - } - $theme->operations[] = array( - 'title' => t('Set default'), - 'href' => 'admin/appearance/default', - 'query' => $query, - 'attributes' => array('title' => t('Set !theme as default theme', array('!theme' => $theme->info['name']))), - ); - } - $admin_theme_options[$theme->name] = $theme->info['name']; - } - else { - $theme->operations[] = array( - 'title' => t('Enable'), - 'href' => 'admin/appearance/enable', - 'query' => $query, - 'attributes' => array('title' => t('Enable !theme theme', array('!theme' => $theme->info['name']))), - ); - $theme->operations[] = array( - 'title' => t('Enable and set default'), - 'href' => 'admin/appearance/default', - 'query' => $query, - 'attributes' => array('title' => t('Enable !theme as default theme', array('!theme' => $theme->info['name']))), - ); - } - } - - // Add notes to default and administration theme. - $theme->notes = array(); - $theme->classes = array(); - if ($theme->is_default) { - $theme->classes[] = 'theme-default'; - $theme->notes[] = t('default theme'); - } - if ($theme->name == $admin_theme || ($theme->is_default && $admin_theme == '0')) { - $theme->classes[] = 'theme-admin'; - $theme->notes[] = t('admin theme'); - } - - // Sort enabled and disabled themes into their own groups. - $theme_groups[$theme->status ? 'enabled' : 'disabled'][] = $theme; - } - - // There are two possible theme groups. - $theme_group_titles = array( - 'enabled' => format_plural(count($theme_groups['enabled']), 'Enabled theme', 'Enabled themes'), - ); - if (!empty($theme_groups['disabled'])) { - $theme_group_titles['disabled'] = format_plural(count($theme_groups['disabled']), 'Disabled theme', 'Disabled themes'); - } - - uasort($theme_groups['enabled'], 'system_sort_themes'); - drupal_alter('system_themes_page', $theme_groups); - - $admin_form = drupal_get_form('system_themes_admin_form', $admin_theme_options); - return theme('system_themes_page', array('theme_groups' => $theme_groups, 'theme_group_titles' => $theme_group_titles)) . drupal_render($admin_form); -} - -/** - * Form to select the administration theme. - * - * @ingroup forms - * @see system_themes_admin_form_submit() - */ -function system_themes_admin_form($form, &$form_state, $theme_options) { - // Administration theme settings. - $form['admin_theme'] = array( - '#type' => 'details', - '#title' => t('Administration theme'), - ); - $form['admin_theme']['admin_theme'] = array( - '#type' => 'select', - '#options' => array(0 => t('Default theme')) + $theme_options, - '#title' => t('Administration theme'), - '#description' => t('Choose "Default theme" to always use the same theme as the rest of the site.'), - '#default_value' => config('system.theme')->get('admin'), - ); - $form['admin_theme']['actions'] = array('#type' => 'actions'); - $form['admin_theme']['actions']['submit'] = array( - '#type' => 'submit', - '#value' => t('Save configuration'), - ); - return $form; -} - -/** - * Process system_themes_admin_form form submissions. - */ -function system_themes_admin_form_submit($form, &$form_state) { - drupal_set_message(t('The configuration options have been saved.')); - config('system.theme')->set('admin', $form_state['values']['admin_theme'])->save(); -} - -/** * Menu callback; Set the default theme. */ function system_theme_default() { @@ -938,26 +773,6 @@ function system_modules($form, $form_state = array()) { } /** - * Array sorting callback; sorts modules or themes by their name. - */ -function system_sort_modules_by_info_name($a, $b) { - return strcasecmp($a->info['name'], $b->info['name']); -} - -/** - * Array sorting callback; sorts modules or themes by their name. - */ -function system_sort_themes($a, $b) { - if ($a->is_default) { - return -1; - } - if ($b->is_default) { - return 1; - } - return strcasecmp($a->info['name'], $b->info['name']); -} - -/** * Build a table row for the system modules page. */ function _system_modules_build_row($info, $extra) { diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 185827e..3268b16 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -686,16 +686,7 @@ function system_menu() { 'file' => 'system.admin.inc', ); // Appearance. - $items['admin/appearance'] = array( - 'title' => 'Appearance', - 'description' => 'Select and configure your themes.', - 'page callback' => 'system_themes_page', - 'access arguments' => array('administer themes'), - 'position' => 'left', - 'weight' => -6, - 'file' => 'system.admin.inc', - ); - $items['admin/appearance/list'] = array( + $items['admin/appearance/list'] = array( 'title' => 'List', 'description' => 'Select and configure your theme', 'type' => MENU_DEFAULT_LOCAL_TASK, @@ -3833,3 +3824,60 @@ function country_get_list() { drupal_alter('countries', $countries); return $countries; } + +/** + * Form to select the administration theme. + * + * @ingroup forms + * @see system_themes_admin_form_submit() + */ +function system_themes_admin_form($form, &$form_state, $theme_options) { + // Administration theme settings. + $form['admin_theme'] = array( + '#type' => 'details', + '#title' => t('Administration theme'), + ); + $form['admin_theme']['admin_theme'] = array( + '#type' => 'select', + '#options' => array(0 => t('Default theme')) + $theme_options, + '#title' => t('Administration theme'), + '#description' => t('Choose "Default theme" to always use the same theme as the rest of the site.'), + '#default_value' => config('system.theme')->get('admin'), + ); + $form['admin_theme']['actions'] = array('#type' => 'actions'); + $form['admin_theme']['actions']['submit'] = array( + '#type' => 'submit', + '#value' => t('Save configuration'), + ); + return $form; +} + +/** + * Process system_themes_admin_form form submissions. + */ +function system_themes_admin_form_submit($form, &$form_state) { + drupal_set_message(t('The configuration options have been saved.')); + config('system.theme')->set('admin', $form_state['values']['admin_theme'])->save(); +} + +/** + * Array sorting callback; sorts modules or themes by their name. + */ +function system_sort_modules_by_info_name($a, $b) { + return strcasecmp($a->info['name'], $b->info['name']); +} + +/** + * Array sorting callback; sorts modules or themes by their name. + */ +function system_sort_themes($a, $b) { + if ($a->is_default) { + return -1; + } + if ($b->is_default) { + return 1; + } + return strcasecmp($a->info['name'], $b->info['name']); +} + + diff --git a/core/modules/system/system.routing.yml b/core/modules/system/system.routing.yml index 6f0e7f5..42e3fe5 100644 --- a/core/modules/system/system.routing.yml +++ b/core/modules/system/system.routing.yml @@ -137,3 +137,10 @@ system_php: requirements: _permission: 'administer site configuration' +system_themes_page: + pattern: '/admin/appearance' + defaults: + _controller: 'Drupal\system\Controller\ThemeController::getAllThemes' + requirements: + _permission: 'administer themes' +