Commit 6afc39c2 authored by webchick's avatar webchick

#135976 by Dave Reid: Move Administration Theme setting to the themes page...

#135976 by Dave Reid: Move Administration Theme setting to the themes page where it is findable (with tests).
parent 1681bc16
...@@ -176,7 +176,7 @@ function block_menu() { ...@@ -176,7 +176,7 @@ function block_menu() {
* Menu item access callback - only admin or enabled themes can be accessed. * Menu item access callback - only admin or enabled themes can be accessed.
*/ */
function _block_themes_access($theme) { function _block_themes_access($theme) {
return user_access('administer blocks') && ($theme->status || $theme->name == variable_get('admin_theme', '0')); return user_access('administer blocks') && ($theme->status || $theme->name == variable_get('admin_theme', 0));
} }
/** /**
......
...@@ -132,41 +132,6 @@ function system_settings_overview() { ...@@ -132,41 +132,6 @@ function system_settings_overview() {
return $output; return $output;
} }
/**
* Form builder; This function allows selection of the theme to show in administration sections.
*
* @ingroup forms
* @see system_settings_form()
*/
function system_admin_theme_settings() {
$themes = system_theme_data();
uasort($themes, 'system_sort_modules_by_info_name');
$options[0] = '<' . t('System default') . '>';
foreach ($themes as $theme) {
$options[$theme->name] = $theme->info['name'];
}
$form['admin_theme'] = array(
'#type' => 'select',
'#options' => $options,
'#title' => t('Administration theme'),
'#description' => t('Choose which theme the administration pages should display in. If you choose "System default" the administration pages will use the same theme as the rest of the site.'),
'#default_value' => '0',
);
$form['node_admin_theme'] = array(
'#type' => 'checkbox',
'#title' => t('Use administration theme for content editing'),
'#description' => t('Use the administration theme when editing existing posts or creating new ones.'),
'#default_value' => '0',
);
$form['#submit'][] = 'system_admin_theme_submit';
return system_settings_form($form, TRUE);
}
/** /**
* Menu callback; displays a listing of all themes. * Menu callback; displays a listing of all themes.
* *
...@@ -174,10 +139,9 @@ function system_admin_theme_settings() { ...@@ -174,10 +139,9 @@ function system_admin_theme_settings() {
* @see system_themes_form_submit() * @see system_themes_form_submit()
*/ */
function system_themes_form() { function system_themes_form() {
drupal_clear_css_cache(); drupal_clear_css_cache();
$themes = system_theme_data();
$themes = system_theme_data();
uasort($themes, 'system_sort_modules_by_info_name'); uasort($themes, 'system_sort_modules_by_info_name');
$status = array(); $status = array();
...@@ -201,9 +165,9 @@ function system_themes_form() { ...@@ -201,9 +165,9 @@ function system_themes_form() {
'#type' => 'value', '#type' => 'value',
'#value' => $theme->info, '#value' => $theme->info,
); );
$options[$theme->name] = ''; $options[$theme->name] = $theme->info['name'];
if (!empty($theme->status) || $theme->name == variable_get('admin_theme', '0')) { if (!empty($theme->status) || $theme->name == variable_get('admin_theme', 0)) {
$form[$theme->name]['operations'] = array('#markup' => l(t('configure'), 'admin/build/themes/settings/' . $theme->name) ); $form[$theme->name]['operations'] = array('#markup' => l(t('configure'), 'admin/build/themes/settings/' . $theme->name) );
} }
else { else {
...@@ -226,16 +190,38 @@ function system_themes_form() { ...@@ -226,16 +190,38 @@ function system_themes_form() {
$form['status'] = array( $form['status'] = array(
'#type' => 'checkboxes', '#type' => 'checkboxes',
'#options' => $options, '#options' => array_fill_keys(array_keys($options), ''),
'#default_value' => $status, '#default_value' => $status,
'#incompatible_themes_core' => drupal_map_assoc($incompatible_core), '#incompatible_themes_core' => drupal_map_assoc($incompatible_core),
'#incompatible_themes_php' => $incompatible_php, '#incompatible_themes_php' => $incompatible_php,
); );
$form['theme_default'] = array( $form['theme_default'] = array(
'#type' => 'radios', '#type' => 'radios',
'#options' => $options, '#options' => array_fill_keys(array_keys($options), ''),
'#default_value' => variable_get('theme_default', 'garland'), '#default_value' => variable_get('theme_default', 'garland'),
); );
// Administration theme settings.
$form['admin_theme'] = array(
'#type' => 'fieldset',
'#title' => t('Administration theme'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['admin_theme']['admin_theme'] = array(
'#type' => 'select',
'#options' => array(0 => t('Default theme')) + $options,
'#title' => t('Administration theme'),
'#description' => t('Choose which theme the administration pages should display in. If you choose "Default theme" the administration pages will use the same theme as the rest of the site.'),
'#default_value' => variable_get('admin_theme', 0),
);
$form['admin_theme']['node_admin_theme'] = array(
'#type' => 'checkbox',
'#title' => t('Use administration theme for content editing'),
'#description' => t('Use the administration theme when editing existing posts or creating new ones.'),
'#default_value' => variable_get('node_admin_theme', '0'),
);
$form['buttons']['submit'] = array( $form['buttons']['submit'] = array(
'#type' => 'submit', '#type' => 'submit',
'#value' => t('Save configuration'), '#value' => t('Save configuration'),
...@@ -244,6 +230,7 @@ function system_themes_form() { ...@@ -244,6 +230,7 @@ function system_themes_form() {
'#type' => 'submit', '#type' => 'submit',
'#value' => t('Reset to defaults'), '#value' => t('Reset to defaults'),
); );
return $form; return $form;
} }
...@@ -272,18 +259,31 @@ function system_themes_form_submit($form, &$form_state) { ...@@ -272,18 +259,31 @@ function system_themes_form_submit($form, &$form_state) {
} }
} }
} }
if (($admin_theme = variable_get('admin_theme', '0')) != '0' && $admin_theme != $form_state['values']['theme_default']) { if ($form_state['values']['admin_theme'] && $form_state['values']['admin_theme'] != $form_state['values']['theme_default']) {
drupal_set_message(t('Please note that the <a href="!admin_theme_page">administration theme</a> 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( drupal_set_message(t('Please note that the <a href="!admin_theme_page">administration theme</a> 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_page' => url('admin/settings/admin'), '!admin_theme_page' => url('admin/settings/admin'),
'%admin_theme' => $admin_theme, '%admin_theme' => $form_state['values']['admin_theme'],
'%selected_theme' => $form_state['values']['theme_default'], '%selected_theme' => $form_state['values']['theme_default'],
))); )));
} }
if ($form_state['values']['admin_theme'] && $form_state['values']['admin_theme'] != variable_get('admin_theme', 0)) {
// If we're changing themes, make sure the theme has its blocks initialized.
$result = db_result(db_query("SELECT COUNT(*) FROM {block} WHERE theme = '%s'", $form_state['values']['admin_theme']));
if (!$result) {
system_initialize_theme_blocks($form_state['values']['admin_theme']);
}
}
// Save the variables.
variable_set('theme_default', $form_state['values']['theme_default']); variable_set('theme_default', $form_state['values']['theme_default']);
variable_set('admin_theme', $form_state['values']['admin_theme']);
variable_set('node_admin_theme', $form_state['values']['node_admin_theme']);
} }
else { else {
// Revert to defaults: only Garland is enabled. // Revert to defaults: only Garland is enabled.
variable_del('theme_default'); variable_del('theme_default');
variable_del('admin_theme');
variable_del('node_admin_theme');
db_query("UPDATE {system} SET status = 1 WHERE type = 'theme' AND name = 'garland'"); db_query("UPDATE {system} SET status = 1 WHERE type = 'theme' AND name = 'garland'");
$new_theme_list = array('garland'); $new_theme_list = array('garland');
} }
......
...@@ -504,26 +504,17 @@ function system_menu() { ...@@ -504,26 +504,17 @@ function system_menu() {
'page callback' => 'system_admin_menu_block_page', 'page callback' => 'system_admin_menu_block_page',
'access arguments' => array('access administration pages'), 'access arguments' => array('access administration pages'),
); );
$items['admin/settings/admin'] = array(
'title' => 'Administration theme',
'description' => 'Settings for how your administrative pages should look.',
'position' => 'left',
'page callback' => 'drupal_get_form',
'page arguments' => array('system_admin_theme_settings'),
'access arguments' => array('administer site configuration'),
'block callback' => 'system_admin_theme_settings',
);
// Themes: // Themes:
$items['admin/build/themes'] = array( $items['admin/build/themes'] = array(
'title' => 'Themes', 'title' => 'Themes',
'description' => 'Change which theme your site uses or allows users to set.', 'description' => 'Change which theme your site uses or allows users to set.',
'page callback' => 'drupal_get_form', 'page callback' => 'drupal_get_form',
'page arguments' => array('system_themes_form', NULL), 'page arguments' => array('system_themes_form'),
'access arguments' => array('administer site configuration'), 'access arguments' => array('administer site configuration'),
); );
$items['admin/build/themes/select'] = array( $items['admin/build/themes/select'] = array(
'title' => 'List', 'title' => 'List',
'description' => 'Select the default theme.', 'description' => 'Select the default theme for your site.',
'type' => MENU_DEFAULT_LOCAL_TASK, 'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -1, 'weight' => -1,
); );
...@@ -782,7 +773,7 @@ function blocked_ip_load($iid) { ...@@ -782,7 +773,7 @@ function blocked_ip_load($iid) {
* Menu item access callback - only admin or enabled themes can be accessed. * Menu item access callback - only admin or enabled themes can be accessed.
*/ */
function _system_themes_access($theme) { function _system_themes_access($theme) {
return user_access('administer site configuration') && ($theme->status || $theme->name == variable_get('admin_theme', '0')); return user_access('administer site configuration') && ($theme->status || $theme->name == variable_get('admin_theme', 0));
} }
/** /**
...@@ -792,7 +783,7 @@ function system_init() { ...@@ -792,7 +783,7 @@ function system_init() {
// Use the administrative theme if the user is looking at a page in the admin/* path. // Use the administrative theme if the user is looking at a page in the admin/* path.
if (arg(0) == 'admin' || (variable_get('node_admin_theme', '0') && arg(0) == 'node' && (arg(1) == 'add' || arg(2) == 'edit'))) { if (arg(0) == 'admin' || (variable_get('node_admin_theme', '0') && arg(0) == 'node' && (arg(1) == 'add' || arg(2) == 'edit'))) {
global $custom_theme; global $custom_theme;
$custom_theme = variable_get('admin_theme', '0'); $custom_theme = variable_get('admin_theme', 0);
drupal_add_css(drupal_get_path('module', 'system') . '/admin.css'); drupal_add_css(drupal_get_path('module', 'system') . '/admin.css');
} }
...@@ -981,19 +972,6 @@ function system_admin_menu_block($item) { ...@@ -981,19 +972,6 @@ function system_admin_menu_block($item) {
return $content; return $content;
} }
/**
* Process admin theme form submissions.
*/
function system_admin_theme_submit($form, &$form_state) {
// If we're changing themes, make sure the theme has its blocks initialized.
if ($form_state['values']['admin_theme'] && $form_state['values']['admin_theme'] != variable_get('admin_theme', '0')) {
$result = db_result(db_query("SELECT COUNT(*) FROM {block} WHERE theme = '%s'", $form_state['values']['admin_theme']));
if (!$result) {
system_initialize_theme_blocks($form_state['values']['admin_theme']);
}
}
}
/** /**
* Returns a fieldset containing the theme select form. * Returns a fieldset containing the theme select form.
* *
......
...@@ -828,3 +828,70 @@ class SystemSettingsForm extends DrupalWebTestCase { ...@@ -828,3 +828,70 @@ class SystemSettingsForm extends DrupalWebTestCase {
$this->assertTrue($no_automatic['has_children']['system_settings_form_test_5']['#default_value']); $this->assertTrue($no_automatic['has_children']['system_settings_form_test_5']['#default_value']);
} }
} }
/**
* Tests for the theme interface functionality.
*/
class SystemThemeFunctionalTest extends DrupalWebTestCase {
function getInfo() {
return array(
'name' => t('Theme interface functionality'),
'description' => t('Tests the theme interface functionality by enabling and switching themes, and using an administration theme.'),
'group' => t('System'),
);
}
function setUp() {
parent::setUp();
$this->admin_user = $this->drupalCreateUser(array('access administration pages', 'administer site configuration', 'bypass node access'));
$this->drupalLogin($this->admin_user);
$this->node = $this->drupalCreateNode();
}
/**
* Test the administration theme functionality.
*/
function testAdministrationTheme() {
// Enable an administration theme and show it on the node admin pages.
$edit = array(
'theme_default' => 'stark',
'admin_theme' => 'garland',
'node_admin_theme' => TRUE,
);
$this->drupalPost('admin/build/themes', $edit, t('Save configuration'));
$this->drupalGet('admin');
$this->assertRaw('themes/garland', t('Administration theme used on an administration page.'));
$this->drupalGet('node/' . $this->node->nid);
$this->assertRaw('themes/stark', t('Site default theme used on node page.'));
$this->drupalGet('node/add');
$this->assertRaw('themes/garland', t('Administration theme used on the add content page.'));
$this->drupalGet('node/' . $this->node->nid . '/edit');
$this->assertRaw('themes/garland', t('Administration theme used on the edit content page.'));
// Disable the admin theme on the node admin pages.
$edit = array(
'node_admin_theme' => FALSE,
);
$this->drupalPost('admin/build/themes', $edit, t('Save configuration'));
$this->drupalGet('admin');
$this->assertRaw('themes/garland', t('Administration theme used on an administration page.'));
$this->drupalGet('node/add');
$this->assertRaw('themes/stark', t('Site default theme used on the add content page.'));
// Reset to the default theme settings.
$this->drupalPost('admin/build/themes', array(), t('Reset to defaults'));
$this->drupalGet('admin');
$this->assertRaw('themes/garland', t('Site default theme used on administration page.'));
$this->drupalGet('node/add');
$this->assertRaw('themes/garland', t('Site default theme used on the add content page.'));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment