Commit 886cc50e authored by Dries's avatar Dries

- Patch #491214 by JohnAlbin, Gábor Hojtsy, eigentor: implement a more usable...

- Patch #491214 by JohnAlbin, Gábor Hojtsy, eigentor: implement a more usable top level Appearance page. Yay.
parent 3db9fc14
......@@ -1242,6 +1242,73 @@ function theme_render_template($template_file, $variables) {
return ob_get_clean(); // End buffering and return its contents
}
/**
* Enable a given list of themes.
*
* @param $theme_list
* An array of theme names.
*/
function theme_enable($theme_list) {
drupal_clear_css_cache();
foreach ($theme_list as $key) {
db_update('system')
->fields(array('status' => 1))
->condition('type', 'theme')
->condition('name', $key)
->execute();
}
list_themes(TRUE);
menu_rebuild();
drupal_theme_rebuild();
// Notify locale module about new themes being enabled, so translations can
// be imported. This might start a batch, and only return to the redirect
// path after that.
module_invoke('locale', 'system_update', $theme_list);
// Invoke hook_themes_enabled after the themes have been enabled.
module_invoke_all('themes_enabled', $theme_list);
return;
}
/**
* Disable a given list of themes.
*
* @param $theme_list
* An array of theme names.
*/
function theme_disable($theme_list) {
// Don't disable the default theme.
if ($pos = array_search(variable_get('theme_default', 'garland'), $theme_list) !== FALSE) {
unset($theme_list[$pos]);
if (empty($theme_list)) {
return;
}
}
drupal_clear_css_cache();
foreach ($theme_list as $key) {
db_update('system')
->fields(array('status' => 0))
->condition('type', 'theme')
->condition('name', $key)
->execute();
}
list_themes(TRUE);
menu_rebuild();
drupal_theme_rebuild();
// Invoke hook_themes_enabled after the themes have been enabled.
module_invoke_all('themes_disabled', $theme_list);
return;
}
/**
* @defgroup themeable Default theme implementations
* @{
......
......@@ -496,35 +496,12 @@ function block_form_user_profile_form_alter(&$form, &$form_state) {
}
}
/**
* Implement hook_form_FORM_ID_alter().
*/
function block_form_system_themes_form_alter(&$form, &$form_state) {
// This function needs to fire before the theme changes are recorded in the
// database, otherwise it will populate the default list of blocks from the
// new theme, which is empty.
array_unshift($form['#submit'], 'block_system_themes_form_submit');
}
/**
* Initialize blocks for enabled themes.
*/
function block_system_themes_form_submit(&$form, &$form_state) {
if ($form_state['values']['op'] == t('Save configuration')) {
if (is_array($form_state['values']['status'])) {
foreach ($form_state['values']['status'] as $key => $choice) {
if ($choice || $form_state['values']['theme_default'] == $key) {
block_theme_initialize($key);
}
}
}
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.
$has_blocks = (bool) db_query_range('SELECT 1 FROM {block} WHERE theme = :theme', 0, 1, array(':theme' => $form_state['values']['admin_theme']))->fetchField();
if (!$has_blocks) {
block_theme_initialize($form_state['values']['admin_theme']);
}
}
function block_themes_enabled($theme_list) {
foreach ($theme_list as $theme) {
block_theme_initialize($theme);
}
}
......
......@@ -237,7 +237,7 @@ class NonDefaultBlockAdmin extends DrupalWebTestCase {
function testNonDefaultBlockAdmin() {
$admin_user = $this->drupalCreateUser(array('administer blocks', 'administer site configuration'));
$this->drupalLogin($admin_user);
$this->drupalPost('admin/appearance', array('status[stark]' => 1), t('Save configuration'));
theme_enable(array('stark'));
$this->drupalGet('admin/structure/block/list/stark');
}
}
......@@ -277,7 +277,8 @@ class NewDefaultThemeBlocks extends DrupalWebTestCase {
// Turn on the Stark theme and ensure that it contains all of the blocks
// that Garland did.
$this->drupalPost('admin/appearance', array('theme_default' => 'stark'), t('Save configuration'));
theme_enable(array('stark'));
variable_set('theme_default', 'stark');
$result = db_query("SELECT * FROM {block} WHERE theme='stark'");
foreach ($result as $block) {
unset($block->theme, $block->bid);
......
......@@ -80,10 +80,7 @@ class MenuIncTestCase extends DrupalWebTestCase {
$this->assertRaw('garland/style.css', t("The default theme's CSS appears on the page."));
// Now enable the theme and request it again.
$admin_user = $this->drupalCreateUser(array('administer site configuration'));
$this->drupalLogin($admin_user);
$this->drupalPost('admin/appearance', array('status[stark]' => 1), t('Save configuration'));
$this->drupalLogout();
theme_enable(array('stark'));
$this->drupalGet('menu-test/theme-callback/use-stark-theme');
$this->assertText('Requested theme: stark. Actual theme: stark.', t('The theme callback system uses an optional theme once it has been enabled.'));
$this->assertRaw('stark/layout.css', t("The optional theme's CSS appears on the page."));
......
......@@ -90,6 +90,29 @@ input.password-confirm {
margin-left: 10px;
margin-right: 0;
}
.system-themes-list-enabled .theme-selector .screenshot,
.system-themes-list-enabled .theme-selector .no-screenshot {
float: right;
margin: 0 0 0 20px;
}
.system-themes-list-disabled .theme-selector {
float: right;
padding: 20px 0 20px 20px;
}
.theme-selector .operations li {
float: right;
border-right: none;
border-left: 1px solid #cdcdcd;
}
.theme-selector .operations li.last {
padding: 0 0.7em 0 0;
border-left: none;
}
.theme-selector .operations li.first {
padding: 0 0 0 0.7em;
}
.password-strength-title {
float: right;
}
......
This diff is collapsed.
......@@ -2672,6 +2672,23 @@ function hook_page_delivery_callback_alter(&$callback) {
}
}
/**
* Alters theme operation links.
*
* @param $theme_groups
* An associative array containing groups of themes.
*
* @see system_themes_page()
*/
function hook_system_themes_page_alter(&$theme_groups) {
foreach ($theme_groups as $state => &$group) {
foreach($theme_groups[$state] as &$theme) {
// Add a foo link to each list of theme operations.
$theme->operations[] = l(t('Foo'), 'admin/appearance/foo', array('query' => array('theme' => $theme->name)));
}
}
}
/**
* Alters inbound URL requests.
*
......
......@@ -522,9 +522,88 @@ html.js .js-hide {
/*
** Styles for the system themes page (admin/appearance)
*/
#system-themes-form div.incompatible {
.system-themes-list {
margin-bottom: 20px;
}
.system-themes-list-disabled {
border-top: 1px solid #cdcdcd;
padding-top: 20px;
}
.system-themes-list h2 {
margin: 0;
}
.theme-selector {
padding-top: 20px;
}
.theme-selector .screenshot,
.theme-selector .no-screenshot {
border: 1px solid #e0e0d8;
padding: 2px;
vertical-align: bottom;
width: 294px;
height: 219px;
line-height: 219px;
text-align: center;
}
.theme-default .screenshot {
border: 1px solid #aaa;
}
.system-themes-list-enabled .theme-selector .screenshot,
.system-themes-list-enabled .theme-selector .no-screenshot {
float: left; /* LTR */
margin: 0 20px 0 0; /* LTR */
}
.system-themes-list-disabled .theme-selector .screenshot,
.system-themes-list-disabled .theme-selector .no-screenshot {
width: 194px;
height: 144px;
line-height: 144px;
}
.theme-selector h3 {
font-weight: normal;
}
.theme-default h3 {
font-weight: bold;
}
.system-themes-list-enabled .theme-selector h3 {
margin-top: 0;
}
.system-themes-list-disabled .theme-selector {
width: 300px;
float: left; /* LTR */
padding: 20px 20px 20px 0; /* LTR */
}
.system-themes-list-enabled .theme-info {
max-width: 940px;
}
.system-themes-list-disabled .theme-info {
min-height: 170px;
}
.theme-selector .incompatible {
margin-top: 10px;
font-weight: bold;
}
.theme-selector .operations {
margin: 10px 0 0 0;
padding: 0;
}
.theme-selector .operations li {
float: left; /* LTR */
margin: 0;
padding: 0 0.7em;
list-style-type: none;
border-right: 1px solid #cdcdcd; /* LTR */
}
.theme-selector .operations li.last {
padding: 0 0 0 0.7em; /* LTR */
border-right: none; /* LTR */
}
.theme-selector .operations li.first {
padding: 0 0.7em 0 0; /* LTR */
}
#system-themes-admin-form {
clear: left;
}
/*
** Password strength indicator
......
......@@ -133,8 +133,8 @@ function system_help($path, $arg) {
*/
function system_theme() {
return array_merge(drupal_common_theme(), array(
'system_themes_form' => array(
'render element' => 'form',
'system_themes_page' => array(
'variables' => array('theme_groups' => NULL),
'file' => 'system.admin.inc',
),
'system_settings_form' => array(
......@@ -581,23 +581,44 @@ function system_menu() {
$items['admin/appearance'] = array(
'title' => 'Appearance',
'description' => 'Select and configure your site theme.',
'page callback' => 'drupal_get_form',
'page arguments' => array('system_themes_form'),
'page callback' => 'system_themes_page',
'access arguments' => array('administer site configuration'),
'position' => 'left',
'weight' => -6,
'file' => 'system.admin.inc',
);
$items['admin/appearance/select'] = array(
$items['admin/appearance/list'] = array(
'title' => 'List',
'description' => 'Select the default theme for your site.',
'description' => 'Select and configure your site theme.',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -1,
'file' => 'system.admin.inc',
);
$items['admin/appearance/enable'] = array(
'title' => 'Enable theme',
'page callback' => 'system_theme_enable',
'access arguments' => array('administer site configuration'),
'type' => MENU_CALLBACK,
'file' => 'system.admin.inc',
);
$items['admin/appearance/disable'] = array(
'title' => 'Disable theme',
'page callback' => 'system_theme_disable',
'access arguments' => array('administer site configuration'),
'type' => MENU_CALLBACK,
'file' => 'system.admin.inc',
);
$items['admin/appearance/default'] = array(
'title' => 'Set default theme',
'page callback' => 'system_theme_default',
'access arguments' => array('administer site configuration'),
'type' => MENU_CALLBACK,
'file' => 'system.admin.inc',
);
$items['admin/appearance/settings'] = array(
'title' => 'Configure',
'title' => 'Settings',
'description' => 'Configure default and theme specific settings.',
'page callback' => 'drupal_get_form',
'page arguments' => array('system_theme_settings'),
'access arguments' => array('administer site configuration'),
'type' => MENU_LOCAL_TASK,
......
......@@ -1185,9 +1185,10 @@ class SystemThemeFunctionalTest extends DrupalWebTestCase {
* Test the administration theme functionality.
*/
function testAdministrationTheme() {
theme_enable(array('stark'));
variable_set('theme_default', 'stark');
// Enable an administration theme and show it on the node admin pages.
$edit = array(
'theme_default' => 'stark',
'admin_theme' => 'garland',
'node_admin_theme' => TRUE,
);
......@@ -1218,8 +1219,8 @@ class SystemThemeFunctionalTest extends DrupalWebTestCase {
$this->assertRaw('themes/stark', t('Site default theme used on the add content page.'));
// Reset to the default theme settings.
variable_set('theme_default', 'garland');
$edit = array(
'theme_default' => 'garland',
'admin_theme' => '0',
'node_admin_theme' => FALSE,
);
......
......@@ -396,22 +396,30 @@ function update_cron() {
}
/**
* Implement hook_form_FORM_ID_alter().
* Implement hook_themes_enabled().
*
* Adds a submit handler to the system modules and themes forms, so that if a
* site admin saves either form, we invalidate the cache of available updates.
* If themes are enabled, we invalidate the cache of available updates.
*/
function update_themes_enabled($themes) {
// Clear all update module caches.
_update_cache_clear();
}
/**
* Implement hook_themes_disabled().
*
* @see _update_cache_clear()
* If themes are disabled, we invalidate the cache of available updates.
*/
function update_form_system_themes_form_alter(&$form, $form_state) {
$form['#submit'][] = 'update_cache_clear_submit';
function update_themes_disabled($themes) {
// Clear all update module caches.
_update_cache_clear();
}
/**
* Implement hook_form_FORM_ID_alter().
*
* Adds a submit handler to the system modules and themes forms, so that if a
* site admin saves either form, we invalidate the cache of available updates.
* Adds a submit handler to the system modules form, so that if a site admin
* saves the form, we invalidate the cache of available updates.
*
* @see _update_cache_clear()
*/
......
......@@ -1075,6 +1075,13 @@ tr.taxonomy-term-divider-bottom {
border-top: 1px dotted #CCC;
}
.theme-selector h3 {
margin: 10px 0;
}
.theme-selector .operations li {
list-style-image: none;
}
/**
* CSS support
*/
......
......@@ -722,6 +722,21 @@ div.admin-panel {
display: block;
}
/* admin/appearance */
#block-system-main #system-themes-page h2 {
font-weight: normal;
text-transform: uppercase;
}
#block-system-main .theme-selector h3 {
font-weight: normal;
}
#block-system-main .theme-default h3 {
font-weight: bold;
}
#block-system-main .system-themes-list-enabled .theme-selector h3 {
margin-top: 0;
}
/* admin/content and admin/people */
#block-system-main dl.multiselect,
#block-system-main dl.multiselect dt,
......
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