Revision 6534ac3b
Added by Andreas Kohlbecker almost 11 years ago
7.x/themes/zen_dataportal/theme-settings.php | ||
---|---|---|
7 | 7 |
* @param $form_state |
8 | 8 |
* A keyed array containing the current state of the form. |
9 | 9 |
*/ |
10 |
function STARTERKIT_form_system_theme_settings_alter(&$form, &$form_state, $form_id = NULL) {
|
|
10 |
function zen_dataportal_form_system_theme_settings_alter(&$form, &$form_state, $form_id = NULL) {
|
|
11 | 11 |
// Work-around for a core bug affecting admin themes. See issue #943212. |
12 | 12 |
if (isset($form_id)) { |
13 | 13 |
return; |
... | ... | |
15 | 15 |
|
16 | 16 |
// Create the form using Forms API: http://api.drupal.org/api/7 |
17 | 17 |
|
18 |
/* -- Delete this line if you want to use this setting |
|
19 |
$form['STARTERKIT_example'] = array( |
|
20 |
'#type' => 'checkbox', |
|
21 |
'#title' => t('STARTERKIT sample setting'), |
|
22 |
'#default_value' => theme_get_setting('STARTERKIT_example'), |
|
23 |
'#description' => t("This option doesn't do anything; it's just an example."), |
|
24 |
); |
|
25 |
// */ |
|
18 |
$which_image = "banner"; |
|
19 |
$form['zen_dataportal'] = array( |
|
20 |
'#type' => 'fieldset', |
|
21 |
'#title' => t($which_image) . ' ' . t('image settings'), |
|
22 |
'#description' => t('If toggled on, the following image will be displayed.'), |
|
23 |
'#attributes' => array('class' => array('theme-settings-bottom')), |
|
24 |
); |
|
25 |
$form['zen_dataportal']['default_' . $which_image] = array( |
|
26 |
'#type' => 'checkbox', |
|
27 |
'#title' => t('Use the default') . t($which_image), |
|
28 |
'#default_value' => theme_get_setting('default_' . $which_image), |
|
29 |
'#tree' => FALSE, |
|
30 |
'#description' => t('Check here if you want the theme to use the image supplied with it.') |
|
31 |
); |
|
32 |
$form['zen_dataportal']['settings'] = array( |
|
33 |
'#type' => 'container', |
|
34 |
'#states' => array( |
|
35 |
// Hide the logo settings when using the default logo. |
|
36 |
'invisible' => array( |
|
37 |
'input[name="default_' . $which_image . '"]' => array('checked' => TRUE), |
|
38 |
), |
|
39 |
), |
|
40 |
); |
|
41 |
|
|
42 |
// If $path is a public:// URI, display the path relative to the files |
|
43 |
// directory; stream wrappers are not end-user friendly. |
|
44 |
$path = theme_get_setting($which_image . '_path'); |
|
45 |
$image = ''; |
|
46 |
if (file_uri_scheme($path) == 'public') { |
|
47 |
$url = file_create_url($path); |
|
48 |
$path = file_uri_target($path); |
|
49 |
$form['zen_dataportal']['settings'][$which_image . '_preview'] = array( |
|
50 |
'#type' => 'item', |
|
51 |
'#title' => t('Preview'), |
|
52 |
'#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>', |
|
53 |
); |
|
54 |
} |
|
55 |
$form['zen_dataportal']['settings'][$which_image . '_path'] = array( |
|
56 |
'#type' => 'textfield', |
|
57 |
'#title' => t('Path to custom') . ' ' . t($which_image), |
|
58 |
'#description' => t('The path to the file you would like to use as your') . ' ' . t($which_image), |
|
59 |
'#default_value' => $path, |
|
60 |
); |
|
61 |
$form['zen_dataportal']['settings'][$which_image . '_upload'] = array( |
|
62 |
'#type' => 'file', |
|
63 |
'#title' => t('Upload') . ' ' . t($which_image), |
|
64 |
'#maxlength' => 40, |
|
65 |
'#description' => t("If you don't have direct file access to the server, use this field to upload your image.") |
|
66 |
); |
|
67 |
|
|
68 |
|
|
69 |
$form['#validate'][] = 'zen_dataportal_theme_settings_validate'; |
|
70 |
$form['#submit'][] = 'zen_dataportal_theme_settings_submit'; |
|
26 | 71 |
|
27 |
// Remove some of the base theme's settings. |
|
28 |
/* -- Delete this line if you want to turn off this setting. |
|
29 |
unset($form['themedev']['zen_wireframes']); // We don't need to toggle wireframes on this site. |
|
30 |
// */ |
|
31 | 72 |
|
32 | 73 |
// We are editing the $form in place, so we don't need to return anything. |
33 | 74 |
} |
75 |
|
|
76 |
/** |
|
77 |
* Process zen_dataportal admin form submissions. |
|
78 |
*/ |
|
79 |
function zen_dataportal_theme_settings_submit($form, &$form_state) { |
|
80 |
|
|
81 |
$values = &$form_state['values']; |
|
82 |
|
|
83 |
// If the user uploaded a new image, save it to a permanent location |
|
84 |
// and use it in place of the default theme-provided file. |
|
85 |
$which_image = "banner"; |
|
86 |
if ($file = $values[$which_image . '_upload']) { |
|
87 |
unset($values[$which_image . '_upload']); |
|
88 |
$filename = file_unmanaged_copy($file->uri); |
|
89 |
$values['default_' .$which_image ] = 0; |
|
90 |
$values[$which_image . '_path'] = $filename; |
|
91 |
$values['toggle_' . $which_image] = 1; |
|
92 |
} |
|
93 |
if (!empty($values[$which_image . '_path'])) { |
|
94 |
$values[$which_image . '_path'] = _system_theme_settings_validate_path($values[$which_image . '_path']); |
|
95 |
} |
|
96 |
|
|
97 |
/* |
|
98 |
* Ok, we are done here the $values will be saved in the theme |
|
99 |
* variable by system_theme_settings_submit($form, &$form_state) |
|
100 |
*/ |
|
101 |
|
|
102 |
} |
|
103 |
|
|
104 |
/** |
|
105 |
* Validator for the system_theme_settings() form. |
|
106 |
*/ |
|
107 |
function zen_dataportal_theme_settings_validate($form, &$form_state) { |
|
108 |
|
|
109 |
$validators = array('file_validate_is_image' => array()); |
|
110 |
|
|
111 |
$which_image = "banner"; |
|
112 |
// Check for a new uploaded logo. |
|
113 |
$file = file_save_upload($which_image . '_upload', $validators); |
|
114 |
if (isset($file)) { |
|
115 |
// File upload was attempted. |
|
116 |
if ($file) { |
|
117 |
// Put the temporary file in form_values so we can save it on submit. |
|
118 |
$form_state['values'][$which_image . '_upload'] = $file; |
|
119 |
} |
|
120 |
else { |
|
121 |
// File upload failed. |
|
122 |
form_set_error($which_image . '_upload', t('The image could not be uploaded.')); |
|
123 |
} |
|
124 |
} |
|
125 |
} |
Also available in: Unified diff
theme settings for custom banner