-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy paththeme-settings.php
More file actions
258 lines (223 loc) · 8.44 KB
/
theme-settings.php
File metadata and controls
258 lines (223 loc) · 8.44 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
<?php
/**
* Implements hook_form_system_theme_settings_alter().
*
* @param $form
* Nested array of form elements that comprise the form.
* @param $form_state
* A keyed array containing the current state of the form.
*/
function uw_form_system_theme_settings_alter(&$form, &$form_state, $form_id = NULL) {
// Work-around for a core bug affecting admin themes. See issue #943212.
if (isset($form_id)) {
return;
}
// Create the form using Forms API: http://api.drupal.org/api/7
$form['uw'] = array(
'#type' => 'fieldset',
'#title' => 'UW Theme',
'#weight' => -40,
);
$form['uw']['extensions'] = array(
'#type' => 'fieldset',
'#title' => t('Extensions'),
);
$form['uw']['extensions']['weather_enabled'] = array(
'#type' => 'checkbox',
'#title' => t('Weather'),
'#default_value' => theme_get_setting('weather_enabled'),
);
$form['uw']['extensions']['menu_columns_enabled'] = array(
'#type' => 'checkbox',
'#title' => t('Menu Columns'),
'#default_value' => theme_get_setting('menu_columns_enabled'),
);
$form['uw']['search'] = array(
'#type' => 'fieldset',
'#title' => t('Search Box'),
);
$form['uw']['search']['show_search'] = array(
'#type' => 'checkbox',
'#title' => t('Show search (in header)'),
'#default_value' => theme_get_setting('show_search'),
);
$form['uw']['search']['search_default_site'] = array(
'#type' => 'radios',
'#title' => t('Default search site'),
'#default_value' => theme_get_setting('search_default_site'),
'#options' => drupal_map_assoc(array( 'UW', 'this site' )),
'#states' => array(
// Hide this search setting if show_search is unchecked
'invisible' => array(
'input[name="show_search"]' => array('checked' => FALSE),
),
),
);
$form['uw']['search']['this_site_url'] = array(
'#type' => 'textfield',
'#title' => t('URL of "this site" (do not include http://)'),
'#default_value' => theme_get_setting('this_site_url'),
'#states' => array(
// Hide this search setting if show_search is unchecked
'invisible' => array(
'input[name="show_search"]' => array('checked' => FALSE),
),
),
);
$form['uw']['search']['search_with'] = array(
'#type' => 'radios',
'#title' => t('Search "this site" with:'),
'#default_value' => theme_get_setting('search_with'),
'#options' => array( 'drupal'=>'Drupal' , 'google'=>'Google (search results may contain ads)' , 'google_cse'=>'Google CSE -- provide your <a href="http://google.com/cse">Custom Search Engine</a> ID below'),
'#states' => array(
// Hide this search setting if show_search is unchecked
'invisible' => array(
'input[name="show_search"]' => array('checked' => FALSE),
),
),
);
$form['uw']['search']['google_cse_id'] = array(
'#type' => 'textfield',
'#title' => t('Google CSE ID'),
'#default_value' => theme_get_setting('google_cse_id'),
'#states' => array(
// Hide this search setting if show_search is unchecked
'invisible' => array(
'input[name="show_search"]' => array('checked' => FALSE),
),
'enabled' => array(
'input[name="search_with"]' => array('value' => 'google_cse'),
),
),
);
$form['uw']['patch_band'] = array(
'#type' => 'fieldset',
'#title' => t('UW "Patch & Band" Logo Options'),
);
$form['uw']['patch_band']['show_patch'] = array(
'#type' => 'checkbox',
'#title' => t('Show patch (W logo)'),
'#default_value' => theme_get_setting('show_patch'),
);
$form['uw']['patch_band']['patch_color'] = array(
'#type' => 'radios',
'#title' => t('Patch color (W logo)'),
'#default_value' => theme_get_setting('patch_color'),
'#options' => drupal_map_assoc(array('gold', 'purple')),
'#states' => array(
// Hide the patch color settings if show_patch is unchecked
'invisible' => array(
'input[name="show_patch"]' => array('checked' => FALSE),
),
),
);
$form['uw']['patch_band']['band_color'] = array(
'#type' => 'radios',
'#title' => t('Band color'),
'#default_value' => theme_get_setting('band_color'),
'#options' => drupal_map_assoc(array('purple', 'tan')),
);
$form['uw']['header'] = array(
'#type' => 'fieldset',
'#title' => t('Header image settings (masthead background)'),
);
$form['uw']['header']['default_header'] = array(
'#type' => 'checkbox',
'#title' => t('Use the default header image'),
'#default_value' => theme_get_setting('default_header'),
'#tree' => FALSE,
'#description' => t('Check here if you want the theme to use the header supplied with it.')
);
$form['uw']['header']['settings'] = array(
'#type' => 'container',
'#states' => array(
// Hide the header settings when using the default header.
'invisible' => array(
'input[name="default_header"]' => array('checked' => TRUE),
),
),
);
$form['uw']['header']['settings']['header_path'] = array(
'#type' => 'textfield',
'#title' => t('Path to custom header'),
'#description' => t('The path to the file you would like to use as your header file instead of the default header.'),
'#default_value' => theme_get_setting('header_path'),
);
$form['uw']['header']['settings']['header_upload'] = array(
'#type' => 'file',
'#title' => t('Upload header image'),
'#maxlength' => 40,
'#description' => t("If you don't have direct file access to the server, use this field to upload your header.")
);
$form['uw']['misc'] = array(
'#type' => 'fieldset',
'#title' => t('Miscellaneous Settings'),
);
$form['uw']['misc']['breadcrumb'] = array(
'#type' => 'checkbox',
'#title' => t('Display breadcrumb links'),
'#default_value' => theme_get_setting('breadcrumb'),
'#description' => t('Check here if you want the breadcrumb links to display.')
);
$form['uw']['misc']['margin_width'] = array(
'#type' => 'radios',
'#title' => t('Margin width'),
'#default_value' => theme_get_setting('margin_width'),
'#options' => drupal_map_assoc(array( 'Default', 'Tight' )),
);
$form['#validate'][] = 'uw_theme_settings_validate';
$form['#submit'][] = 'uw_theme_settings_submit';
// We are editing the $form in place, so we don't need to return anything.
}
/**
* Validator for the system_theme_settings() form.
*/
function uw_theme_settings_validate($form, &$form_state) {
// Handle file uploads.
$validators = array('file_validate_is_image' => array());
// Check for a new uploaded logo.
$file = file_save_upload('header_upload', $validators);
if (isset($file)) {
// File upload was attempted.
if ($file) {
// Put the temporary file in form_values so we can save it on submit.
$form_state['values']['header_upload'] = $file;
}
else {
// File upload failed.
form_set_error('header_upload', t('The header could not be uploaded.'));
}
}
// If the user provided a path for a header file, make sure a file
// exists at that path.
if ($form_state['values']['header_path']) {
$path = _system_theme_settings_validate_path($form_state['values']['header_path']);
if (!$path) {
form_set_error('header_path', t('The custom header path is invalid.'));
}
}
// If they checked CSE be sure they provided a CSE ID
if ( $form_state['values']['search_with'] == 'google_cse' && $form_state['values']['google_cse_id'] == '' ) {
form_set_error('google_cse_id', t('You selected "Google with your CSE" but did not provide a CSE Identifier.') );
}
}
/**
* Process system_theme_settings form submissions.
*/
function uw_theme_settings_submit($form, &$form_state) {
$values = &$form_state['values'];
// If the user uploaded a new header, save it to a permanent location
// and use it in place of the default theme-provided file.
if ($file = $values['header_upload']) {
unset($values['header_upload']);
$filename = file_unmanaged_copy($file->uri);
$values['default_header'] = 0;
$values['header_path'] = $filename;
$values['toggle_header'] = 1;
}
// If the user entered a path relative to the system files directory for
// a header image, store a public:// URI so the theme system can handle it.
if (!empty($values['header_path'])) {
$values['header_path'] = _system_theme_settings_validate_path($values['header_path']);
}
}