summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohnAlbin2008-05-13 09:19:13 (GMT)
committer JohnAlbin2008-05-13 09:19:13 (GMT)
commit7b846edfb8145f77f87ce70dcfe72f8a767dbabf (patch)
treef094de84b1fe39c7a5da87af60c0d66fe84b1ecd
parent29040f09071ab59a4cb87b3bd6b4a5315671d4ee (diff)
#248103: Allow themes to set defaults for settings in their .info files
-rw-r--r--CHANGELOG.txt3
-rw-r--r--STARTERKIT/STARTERKIT.info9
-rw-r--r--STARTERKIT/template.php6
-rw-r--r--STARTERKIT/theme-settings-init.php37
-rw-r--r--STARTERKIT/theme-settings.php20
-rw-r--r--zen/template.php46
-rw-r--r--zen/theme-settings-init.php63
-rw-r--r--zen/theme-settings.php23
-rw-r--r--zen/zen.info10
-rw-r--r--zen_classic/template.php6
-rw-r--r--zen_classic/theme-settings-init.php37
-rw-r--r--zen_classic/theme-settings.php20
-rw-r--r--zen_classic/zen_classic.info11
13 files changed, 91 insertions, 200 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 68b4e91..8bea5c4 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -1,6 +1,5 @@
Zen 6.x-1.x-dev
- * Upgrading to Drupal 6. Not yet complete.
-
+ #248103: Allow themes to set defaults for settings in their .info files
#249532: Allow subthemes to have preprocess hooks without tpl files
#223518: Option to show page title in breadcrumbs
#253249: zen_id_safe fails when first character is extended latin
diff --git a/STARTERKIT/STARTERKIT.info b/STARTERKIT/STARTERKIT.info
index 1e830fe..2af503c 100644
--- a/STARTERKIT/STARTERKIT.info
+++ b/STARTERKIT/STARTERKIT.info
@@ -68,3 +68,12 @@ features[] = search
features[] = favicon
features[] = primary_links
features[] = secondary_links
+
+ ; Set the default settings to be used in theme-settings.php
+settings[zen_block_editing] = 1
+settings[zen_breadcrumb] = yes
+settings[zen_breadcrumb_separator] = ' › '
+settings[zen_breadcrumb_home] = 1
+settings[zen_breadcrumb_trailing] = 1
+settings[zen_breadcrumb_title] = 0
+settings[zen_wireframes] = 0
diff --git a/STARTERKIT/template.php b/STARTERKIT/template.php
index a7ea87f..4c6241a 100644
--- a/STARTERKIT/template.php
+++ b/STARTERKIT/template.php
@@ -28,12 +28,6 @@
/*
- * Initialize theme settings
- */
-include_once 'theme-settings-init.php';
-
-
-/*
* Add any conditional stylesheets you will need for this sub-theme.
*
* To add stylesheets that ALWAYS need to be included, you should add them to
diff --git a/STARTERKIT/theme-settings-init.php b/STARTERKIT/theme-settings-init.php
deleted file mode 100644
index 8dba0f5..0000000
--- a/STARTERKIT/theme-settings-init.php
+++ /dev/null
@@ -1,37 +0,0 @@
-<?php
-// $Id$
-
-if (is_null(theme_get_setting('zen_breadcrumb_title'))) {
- global $theme_key;
-
- /*
- * Modify the values in $defaults below if you want the subtheme to have
- * different defaults than the main Zen theme. Make sure $defaults exactly
- * matches the $defaults in the theme-settings.php file.
- */
- $defaults = array(
- 'zen_block_editing' => 1,
- 'zen_breadcrumb' => 'yes',
- 'zen_breadcrumb_separator' => ' › ',
- 'zen_breadcrumb_home' => 1,
- 'zen_breadcrumb_trailing' => 1,
- 'zen_breadcrumb_title' => 0,
- 'zen_wireframes' => 0,
- );
-
- // Get default theme settings.
- $settings = theme_get_settings($theme_key);
- // Don't save the toggle_node_info_ variables.
- if (module_exists('node')) {
- foreach (node_get_types() as $type => $name) {
- unset($settings['toggle_node_info_' . $type]);
- }
- }
- // Save default theme settings.
- variable_set(
- str_replace('/', '_', 'theme_' . $theme_key . '_settings'),
- array_merge($defaults, $settings)
- );
- // Force refresh of Drupal internals.
- theme_get_setting('', TRUE);
-}
diff --git a/STARTERKIT/theme-settings.php b/STARTERKIT/theme-settings.php
index 70e6d83..903fe13 100644
--- a/STARTERKIT/theme-settings.php
+++ b/STARTERKIT/theme-settings.php
@@ -11,25 +11,15 @@
*/
function STARTERKIT_settings($saved_settings) {
- /*
- * The default values for the theme variables. Make sure $defaults exactly
- * matches the $defaults in the theme-settings-init.php file.
- */
- $defaults = array(
- 'zen_block_editing' => 1,
- 'zen_breadcrumb' => 'yes',
- 'zen_breadcrumb_separator' => ' › ',
- 'zen_breadcrumb_home' => 1,
- 'zen_breadcrumb_trailing' => 1,
- 'zen_breadcrumb_title' => 0,
- 'zen_wireframes' => 0,
- );
+ // Get the default values from the .info file.
+ $themes = list_themes();
+ $defaults = $themes['STARTERKIT']->info['settings'];
- // Merge the saved variables and their default values
+ // Merge the saved variables and their default values.
$settings = array_merge($defaults, $saved_settings);
/*
- * Create the form using Forms API: http://api.drupal.org/api/5
+ * Create the form using Forms API: http://api.drupal.org/api/6
*/
$form = array();
/* -- Delete this line if you want to use this setting
diff --git a/zen/template.php b/zen/template.php
index 03e9614..5ebb242 100644
--- a/zen/template.php
+++ b/zen/template.php
@@ -29,9 +29,6 @@
* this main template.php file.
*/
-// Initialize theme settings
-include_once 'theme-settings-init.php';
-
// Tabs and menu functions
include_once 'template-menus.php';
@@ -429,6 +426,49 @@ function zen_theme(&$existing, $type, $theme, $path) {
}
}
}
+
+ // Since we are rebuilding the theme registry and the theme settings' default
+ // values may have changed, make sure they are saved in the database properly.
+ zen_settings_init($theme);
+
// Since we modify the $existing cache directly, return nothing.
return array();
}
+
+/**
+ * Read the theme settings' default values from the .info and save them into the database.
+ *
+ * @param $theme
+ * The actual name of theme that is being being checked.
+ */
+function zen_settings_init($theme) {
+ $themes = list_themes();
+
+ // Get the default values from the .info file.
+ $defaults = $themes[$theme]->info['settings'];
+
+ // Get the theme settings saved in the database.
+ $settings = theme_get_settings($theme);
+ // Don't save the toggle_node_info_ variables.
+ if (module_exists('node')) {
+ foreach (node_get_types() as $type => $name) {
+ unset($settings['toggle_node_info_' . $type]);
+ }
+ }
+ // Save default theme settings.
+ variable_set(
+ str_replace('/', '_', 'theme_' . $theme . '_settings'),
+ array_merge($defaults, $settings)
+ );
+ // Force refresh of Drupal internals.
+ theme_get_setting('', TRUE);
+}
+
+/*
+ * In addition to initializing the theme settings during HOOK_theme(), init them
+ * when viewing/resetting the admin/build/themes/settings/THEME forms.
+ */
+if (arg(0) == 'admin' && arg(2) == 'themes' && arg(4)) {
+ global $theme_key;
+ zen_settings_init($theme_key);
+}
diff --git a/zen/theme-settings-init.php b/zen/theme-settings-init.php
deleted file mode 100644
index d89cbb1..0000000
--- a/zen/theme-settings-init.php
+++ /dev/null
@@ -1,63 +0,0 @@
-<?php
-// $Id$
-
-if (is_null(theme_get_setting('zen_breadcrumb_title'))) {
-
- /*
- * init_theme() loads the base theme's template.php before the sub-themes'
- * template.php. So we need to ensure that the sub-themes' theme settings init
- * are loaded first.
- *
- * @FIXME: Implement a default theme settings mechanism that isn't gawd awful: #248103
- */
- global $theme;
- if ($theme != 'zen') {
- $themes = list_themes();
- // Load the active theme and its ancestors.
- $ancestor = $theme;
- while ($ancestor && isset($themes[$ancestor]->base_theme)) {
- // First include theme's template.php.
- $file = dirname($themes[$ancestor]->filename) . '/template.php';
- if (file_exists($file)) {
- include_once "./$file";
- }
- // Then find theme's parent.
- $ancestor = $themes[$ancestor]->base_theme;
- }
- }
-
- if (is_null(theme_get_setting('zen_breadcrumb_title'))) {
- global $theme_key;
-
- /*
- * The default values for the theme variables. Make sure $defaults exactly
- * matches the $defaults in the theme-settings.php file.
- */
- $defaults = array(
- 'zen_block_editing' => 1,
- 'zen_breadcrumb' => 'yes',
- 'zen_breadcrumb_separator' => ' › ',
- 'zen_breadcrumb_home' => 1,
- 'zen_breadcrumb_trailing' => 1,
- 'zen_breadcrumb_title' => 0,
- 'zen_layout' => 'border-politics-liquid',
- 'zen_wireframes' => 0,
- );
-
- // Get default theme settings.
- $settings = theme_get_settings($theme_key);
- // Don't save the toggle_node_info_ variables.
- if (module_exists('node')) {
- foreach (node_get_types() as $type => $name) {
- unset($settings['toggle_node_info_' . $type]);
- }
- }
- // Save default theme settings.
- variable_set(
- str_replace('/', '_', 'theme_' . $theme_key . '_settings'),
- array_merge($defaults, $settings)
- );
- // Force refresh of Drupal internals.
- theme_get_setting('', TRUE);
- }
-}
diff --git a/zen/theme-settings.php b/zen/theme-settings.php
index d534b4c..96b91db 100644
--- a/zen/theme-settings.php
+++ b/zen/theme-settings.php
@@ -19,27 +19,18 @@ function zen_settings($saved_settings, $subtheme_defaults = array()) {
// Add javascript to show/hide optional settings
drupal_add_js(drupal_get_path('theme', 'zen') . '/theme-settings.js', 'theme');
- /*
- * The default values for the theme variables. Make sure $defaults exactly
- * matches the $defaults in the theme-settings-init.php file.
- */
- $defaults = array(
- 'zen_block_editing' => 1,
- 'zen_breadcrumb' => 'yes',
- 'zen_breadcrumb_separator' => ' › ',
- 'zen_breadcrumb_home' => 1,
- 'zen_breadcrumb_trailing' => 1,
- 'zen_breadcrumb_title' => 0,
- 'zen_layout' => 'border-politics-liquid',
- 'zen_wireframes' => 0,
- );
+ // Get the default values from the .info file.
+ $themes = list_themes();
+ $defaults = $themes['zen']->info['settings'];
+
+ // Allow a subtheme to override the default values.
$defaults = array_merge($defaults, $subtheme_defaults);
- // Merge the saved variables and their default values
+ // Merge the saved variables and their default values.
$settings = array_merge($defaults, $saved_settings);
/*
- * Create the form using Form API
+ * Create the form using Forms API
*/
$form['zen-div-opening'] = array(
'#value' => '<div id="zen-settings">',
diff --git a/zen/zen.info b/zen/zen.info
index 90c2540..d7fc976 100644
--- a/zen/zen.info
+++ b/zen/zen.info
@@ -64,3 +64,13 @@ features[] = search
features[] = favicon
features[] = primary_links
features[] = secondary_links
+
+ ; Set the default settings to be used in theme-settings.php
+settings[zen_block_editing] = 1
+settings[zen_breadcrumb] = yes
+settings[zen_breadcrumb_separator] = ' › '
+settings[zen_breadcrumb_home] = 1
+settings[zen_breadcrumb_trailing] = 1
+settings[zen_breadcrumb_title] = 0
+settings[zen_layout] = border-politics-liquid
+settings[zen_wireframes] = 0
diff --git a/zen_classic/template.php b/zen_classic/template.php
index 0b8afa2..34b5422 100644
--- a/zen_classic/template.php
+++ b/zen_classic/template.php
@@ -28,12 +28,6 @@
/*
- * Initialize theme settings
- */
-include_once 'theme-settings-init.php';
-
-
-/*
* Add any conditional stylesheets you will need for this sub-theme.
*
* To add stylesheets that ALWAYS need to be included, you should add them to
diff --git a/zen_classic/theme-settings-init.php b/zen_classic/theme-settings-init.php
deleted file mode 100644
index 1457938..0000000
--- a/zen_classic/theme-settings-init.php
+++ /dev/null
@@ -1,37 +0,0 @@
-<?php
-// $Id$
-
-if (is_null(theme_get_setting('zen_breadcrumb_title'))) {
- global $theme_key;
-
- /*
- * Modify the values in $defaults below if you want the subtheme to have
- * different defaults than the main Zen theme. Make sure $defaults exactly
- * matches the $defaults in the theme-settings.php file.
- */
- $defaults = array(
- 'zen_classic_fixed' => 0,
- 'zen_block_editing' => 1,
- 'zen_breadcrumb' => 'yes',
- 'zen_breadcrumb_separator' => ' :: ',
- 'zen_breadcrumb_home' => 1,
- 'zen_breadcrumb_trailing' => 0,
- 'zen_breadcrumb_title' => 0,
- );
-
- // Get default theme settings.
- $settings = theme_get_settings($theme_key);
- // Don't save the toggle_node_info_ variables.
- if (module_exists('node')) {
- foreach (node_get_types() as $type => $name) {
- unset($settings['toggle_node_info_' . $type]);
- }
- }
- // Save default theme settings.
- variable_set(
- str_replace('/', '_', 'theme_' . $theme_key . '_settings'),
- array_merge($defaults, $settings)
- );
- // Force refresh of Drupal internals.
- theme_get_setting('', TRUE);
-}
diff --git a/zen_classic/theme-settings.php b/zen_classic/theme-settings.php
index b68e85c..676de74 100644
--- a/zen_classic/theme-settings.php
+++ b/zen_classic/theme-settings.php
@@ -11,25 +11,15 @@
*/
function zen_classic_settings($saved_settings) {
- /*
- * The default values for the theme variables. Make sure $defaults exactly
- * matches the $defaults in the theme-settings-init.php file.
- */
- $defaults = array(
- 'zen_classic_fixed' => 0,
- 'zen_block_editing' => 1,
- 'zen_breadcrumb' => 'yes',
- 'zen_breadcrumb_separator' => ' :: ',
- 'zen_breadcrumb_home' => 1,
- 'zen_breadcrumb_trailing' => 0,
- 'zen_breadcrumb_title' => 0,
- );
+ // Get the default values from the .info file.
+ $themes = list_themes();
+ $defaults = $themes['zen_classic']->info['settings'];
- // Merge the saved variables and their default values
+ // Merge the saved variables and their default values.
$settings = array_merge($defaults, $saved_settings);
/*
- * Create the form using Forms API: http://api.drupal.org/api/5
+ * Create the form using Forms API: http://api.drupal.org/api/6
*/
$form = array();
$form['zen_classic_fixed'] = array(
diff --git a/zen_classic/zen_classic.info b/zen_classic/zen_classic.info
index 48b8db2..2896f11 100644
--- a/zen_classic/zen_classic.info
+++ b/zen_classic/zen_classic.info
@@ -69,3 +69,14 @@ features[] = search
features[] = favicon
features[] = primary_links
features[] = secondary_links
+
+ ; Set the default settings to be used in theme-settings.php
+settings[zen_classic_fixed] = 0
+settings[zen_block_editing] = 1
+settings[zen_breadcrumb] = yes
+settings[zen_breadcrumb_separator] = ' :&#58; '
+settings[zen_breadcrumb_home] = 1
+settings[zen_breadcrumb_trailing] = 0
+settings[zen_breadcrumb_title] = 0
+settings[zen_layout] = border-politics-liquid
+settings[zen_wireframes] = 0