-
Notifications
You must be signed in to change notification settings - Fork 1
/
theme-settings.php
131 lines (110 loc) · 5.5 KB
/
theme-settings.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
function watershed_settings($saved_settings, $subtheme_defaults = array()) {
// Get the default values from the .info file.
$defaults = watershed_theme_get_default_settings('watershed');
// Merge the saved variables and their default values.
$settings = array_merge($defaults, $saved_settings);
/*
* Create the form using Forms API
*/
$form['watershed_wn_credit'] = array(
'#type' => 'checkbox',
'#title' => t('Enable Watershed Now Distribution credit'),
'#default_value' => $settings['watershed_wn_credit'],
'#description' => t('Help spread the word about the Watershed Now Drupal Distribution.'),
'#prefix' => '<strong>' . t('Enable WN Credit:') . '</strong>',
);
$form['watershed_zen_tabs'] = array(
'#type' => 'checkbox',
'#title' => t('Use Zen Tabs'),
'#default_value' => $settings['watershed_zen_tabs'],
'#description' => t('Replace the default tabs by the Zen Tabs.'),
'#prefix' => '<strong>' . t('Zen Tabs:') . '</strong>',
);
$form['watershed_breadcrumb'] = array(
'#type' => 'checkbox',
'#title' => t('Enable Breadcrumb trail'),
'#default_value' => $settings['watershed_breadcrumb'],
'#description' => t('Enable breadcrumb trail.'),
'#prefix' => '<strong>' . t('Enable Breadcrumb:') . '</strong>',
);
$form['watershed_wireframe'] = array(
'#type' => 'checkbox',
'#title' => t('Display borders around main layout elements'),
'#default_value' => $settings['watershed_wireframe'],
'#description' => t('<a href="!link">Wireframes</a> are useful when prototyping a website.', array('!link' => 'http://www.boxesandarrows.com/view/html_wireframes_and_prototypes_all_gain_and_no_pain')),
'#prefix' => '<strong>' . t('Wireframes:') . '</strong>',
);
$form['watershed_block_editing'] = array(
'#type' => 'checkbox',
'#title' => t('Show block editing on hover'),
'#description' => t('When hovering over a block, privileged users will see block editing links.'),
'#default_value' => $settings['watershed_block_editing'],
'#prefix' => '<strong>' . t('Block Edit Links:') . '</strong>',
);
$form['themedev']['watershed_rebuild_registry'] = array(
'#type' => 'checkbox',
'#title' => t('Rebuild theme registry on every page.'),
'#default_value' => $settings['watershed_rebuild_registry'],
'#description' => t('During theme development, it can be very useful to continuously <a href="!link">rebuild the theme registry</a>. WARNING: this is a huge performance penalty and must be turned off on production websites.', array('!link' => 'http://drupal.org/node/173880#theme-registry')),
'#prefix' => '<div id="div-watershed-registry"><strong>' . t('Theme registry:') . '</strong>',
'#suffix' => '</div>',
);
// Return the form
return $form;
}
function _watershed_theme(&$existing, $type, $theme, $path) {
// Each theme has two possible preprocess functions that can act on a hook.
// This function applies to every hook.
$functions[0] = $theme . '_preprocess';
// Inspect the preprocess functions for every hook in the theme registry.
// @TODO: When PHP 5 becomes required (Zen 7.x), use the following faster
// implementation: foreach ($existing AS $hook => &$value) {}
foreach (array_keys($existing) AS $hook) {
// Each theme has two possible preprocess functions that can act on a hook.
// This function only applies to this hook.
$functions[1] = $theme . '_preprocess_' . $hook;
foreach ($functions AS $key => $function) {
// Add any functions that are not already in the registry.
if (function_exists($function) && !in_array($function, $existing[$hook]['preprocess functions'])) {
// We add the preprocess function to the end of the existing list.
$existing[$hook]['preprocess functions'][] = $function;
}
}
}
// 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.
watershed_theme_get_default_settings($theme);
// If we are auto-rebuilding the theme registry, warn about feature.
if (theme_get_setting('watershed_rebuild_registry')) {
drupal_set_message(t('The theme registry has been rebuilt. <a href="!link">Turn off</a> this feature on production websites.', array('!link' => base_path() . 'admin/build/themes/settings/' . $GLOBALS['theme'])), 'warning');
}
// Since we modify the $existing cache directly, return nothing.
return array();
}
function watershed_theme_get_default_settings($theme) {
$themes = list_themes();
// Get the default values from the .info file.
$defaults = !empty($themes[$theme]->info['settings']) ? $themes[$theme]->info['settings'] : array();
if (!empty($defaults)) {
// 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)
);
// If the active theme has been loaded, force refresh of Drupal internals.
if (!empty($GLOBALS['theme_key'])) {
theme_get_setting('', TRUE);
}
}
// Return the default settings.
return $defaults;
}