Projet

Général

Profil

Paste
Télécharger (13,3 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / themes / adaptivetheme / at_core / theme-settings.php @ 87dbc3bf

1
<?php
2

    
3
/**
4
 * @file
5
 * Implimentation of hook_form_system_theme_settings_alter()
6
 *
7
 * @param $form: Nested array of form elements that comprise the form.
8
 * @param $form_state: A keyed array containing the current state of the form.
9
 */
10
function adaptivetheme_form_system_theme_settings_alter(&$form, &$form_state, $form_id = NULL) {
11
  // Get our plugin system functions.
12
  require_once(drupal_get_path('theme', 'adaptivetheme') . '/inc/plugins.inc');
13

    
14
  // We need some getters.
15
  require_once(drupal_get_path('theme', 'adaptivetheme') . '/inc/get.inc');
16
  $path_to_at_core = drupal_get_path('theme', 'adaptivetheme');
17

    
18
  // General "alters" use a form id. Settings should not be set here. The only
19
  // thing useful about this is if you need to alter the form for the running
20
  // theme and *not* the theme setting.
21
  // @see http://drupal.org/node/943212
22
  if (isset($form_id)) {
23
    return;
24
  }
25

    
26
  // Get the active theme name, we need it at some stage.
27
  $theme_name = $form_state['build_info']['args'][0];
28

    
29
  // Get the active themes info array
30
  $info_array = at_get_info($theme_name);
31

    
32
  // Set up variables for legacy and non-legacy themes
33
  $legacy_theme = FALSE;
34
  if (!isset($info_array['release']) || $info_array['release'] === '7.x-2.x') {
35
    $legacy_theme = TRUE;
36
  }
37
  elseif (isset($legacy_info['release']) && $legacy_info['release'] === '7.x-3.x') {
38
    $legacy_theme = FALSE;
39
  }
40

    
41
  // Version messages
42
  $version_message = '';
43
  if (at_get_setting('atcore_version_test', $theme_name) === 1) {
44
    if ($legacy_theme == TRUE) {
45
      $version_message = t('<p>The version of your theme (@theme) is not designed to run on <a href="!link_project" target="_blank">Adaptivetheme 7.x.3.x</a>. It will probably run, but your experience will not be optimal. You have three courses of action to choose from:</p>', array('!link_project' => 'http://drupal.org/project/adaptivetheme', '@theme' => $theme_name));
46
      $version_message .= t('<ol><li>Downgrade Adaptivetheme to 7.x-2.x</li><li>Upgrade your theme to the 7.x-3.x branch&thinsp;&mdash;&thinsp;you will need to check if an upgrade exists.</li><li>Add the line <code>"release = 7.x-3.x"</code> (less quotes) to your sub-themes info file and clear the cache to make this message go away.</li></ol>');
47
      $version_message .= t('<p>You can turn off this message in the Debug settings, look for "Sub-theme compatibility test".</p>');
48
      drupal_set_message(filter_xss_admin($version_message), 'warning');
49
    }
50
    elseif ($legacy_theme == FALSE) {
51
      $version_message = t('<p>This theme (@theme) is compatible with <a href="!link_project" target="_blank">Adaptivetheme 7.x.3.x</a>. You are good to go! You can turn off this message in the Debug settings, look for "Sub-theme compatibility test".</p>', array('!link_project' => 'http://drupal.org/project/adaptivetheme', '@theme' => $theme_name));
52
      drupal_set_message(filter_xss_admin($version_message), 'status');
53
    }
54
  }
55

    
56
  // Get the admin theme so we can set a class for styling this form,
57
  // variable_get() returns 0 if the admin theme is the default theme.
58
  $admin_theme = variable_get('admin_theme') ? variable_get('admin_theme') : $theme_name;
59
  $admin_theme_class = 'admin-theme-' . drupal_html_class($admin_theme);
60

    
61
  // LAYOUT SETTINGS
62
  // Build a custom header for the layout settings form.
63
  $logo = file_create_url(drupal_get_path('theme', 'adaptivetheme') . '/logo.png');
64
  $layout_header  = '<div class="at-settings-form layout-settings-form ' . $admin_theme_class . '"><div class="layout-header theme-settings-header clearfix">';
65
  $layout_header .= '<h1>' . t('Layout &amp; General Settings') . '</h1>';
66
  $layout_header .= '<p class="docs-link"><a href="http://adaptivethemes.com/documentation/adaptivetheme-7x-3x" title="View online documentation" target="_blank">View online documentation</a></p>';
67
  $layout_header .= '<p class="logo-link"><a href="http://adaptivethemes.com" title="Adaptivethemes.com - Rocking the hardest since 2006" target="_blank"><img class="at-logo" src="' . $logo . '" /></a></p>';
68
  $layout_header .= '</div>';
69

    
70
  // INCLUDES
71
  $includes_array = array(
72
    'pagelayout',
73
    'responsivepanels',
74
    'global',
75
    'filemanagement',
76
    'css',
77
    'polyfills',
78
    'metatags',
79
    'debug',
80
    'extensions',
81
  );
82
  foreach ($includes_array as $include_file) {
83
    require_once($path_to_at_core . '/inc/forms/settings.' . $include_file . '.inc');
84
  }
85

    
86
  $form['at-settings'] = array(
87
    '#type' => 'vertical_tabs',
88
    '#description' => t('Layout'),
89
    '#prefix' => $layout_header,
90
    '#suffix' => '</div>',
91
    '#weight' => -10,
92
    '#attached' => array(
93
      'css' => array(drupal_get_path('theme', 'adaptivetheme') . '/css/at.settings.form.css'),
94
    ),
95
  );
96

    
97
  // Call all the default settings forms.
98
  at_core_page_layout_form($form, $theme_name);
99
  at_core_responsive_panels_form($form, $theme_name, $info_array);
100
  at_core_global_form($form, $theme_name);
101
  at_core_filemanagement_form($form, $theme_name);
102
  at_core_css_form($form, $theme_name);
103
  at_core_polyfills_form($form, $theme_name);
104
  at_core_metatags_form($form);
105
  at_core_debug_form($form);
106
  at_core_extensions_form($form);
107

    
108
  // EXTENSIONS
109
  $enable_extensions = isset($form_state['values']['enable_extensions']);
110
  if (($enable_extensions && $form_state['values']['enable_extensions'] == 1) || (!$enable_extensions && $form['at-settings']['extend']['enable_extensions']['#default_value'] == 1)) {
111

    
112
    // Build a custom header for the Extensions settings form.
113
    $styles_header  = '<div class="at-settings-form style-settings-form ' . $admin_theme_class . '"><div class="styles-header theme-settings-header clearfix">';
114
    $styles_header .= '<h1>' . t('Extensions') . '</h1>';
115
    $styles_header .= '<p class="docs-link"><a href="http://adaptivethemes.com/documentation/extensions" title="View online documentation for Extensions" target="_blank">View online documentation</a></p>';
116
    $styles_header .= '</div>';
117

    
118
    $form['at'] = array('#type' => 'vertical_tabs',
119
      '#weight' => -9,
120
      '#prefix' => $styles_header,
121
      '#suffix' => '</div>',
122
    );
123

    
124
    // Include fonts.inc by default, the conditional logic to wrap around this is
125
    // too hairy to even comtemplate.
126
    require_once($path_to_at_core . '/inc/fonts.inc');
127

    
128
    // Fonts
129
    $enable_font_settings = isset($form_state['values']['enable_font_settings']);
130
    if (($enable_font_settings && $form_state['values']['enable_font_settings'] == 1) || (!$enable_font_settings && $form['at-settings']['extend']['enable']['enable_font_settings']['#default_value'] == 1)) {
131
      require_once($path_to_at_core . '/inc/forms/settings.fonts.inc');
132
      at_core_fonts_form($form);
133
    }
134

    
135
    // Heading styles
136
    $enable_heading_settings = isset($form_state['values']['enable_heading_settings']);
137
    if (($enable_heading_settings && $form_state['values']['enable_heading_settings'] == 1) || (!$enable_heading_settings && $form['at-settings']['extend']['enable']['enable_heading_settings']['#default_value'] == 1)) {
138
      require_once($path_to_at_core . '/inc/forms/settings.headings.inc');
139
      at_core_headings_form($form);
140
    }
141

    
142
    // Image alignment
143
    $enable_image_settings = isset($form_state['values']['enable_image_settings']);
144
    if (($enable_image_settings && $form_state['values']['enable_image_settings'] == 1) || (!$enable_image_settings && $form['at-settings']['extend']['enable']['enable_image_settings']['#default_value'] == 1)) {
145
      require_once($path_to_at_core . '/inc/forms/settings.images.inc');
146
      at_core_images_form($form);
147
    }
148

    
149
    // Exclude CSS
150
    $enable_exclude_css = isset($form_state['values']['enable_exclude_css']);
151
    if (($enable_exclude_css && $form_state['values']['enable_exclude_css'] == 1) || (!$enable_exclude_css && $form['at-settings']['extend']['enable']['enable_exclude_css']['#default_value'] == 1)) {
152
      require_once($path_to_at_core . '/inc/forms/settings.cssexclude.inc');
153
      at_core_css_exclude_form($form, $theme_name);
154
    }
155

    
156
    // Touch icons
157
    $enable_apple_touch_icons = isset($form_state['values']['enable_apple_touch_icons']);
158
    if (($enable_apple_touch_icons && $form_state['values']['enable_apple_touch_icons'] == 1) || (!$enable_apple_touch_icons && $form['at-settings']['extend']['enable']['enable_apple_touch_icons']['#default_value'] == 1)) {
159
      require_once($path_to_at_core . '/inc/forms/settings.touchicons.inc');
160
      at_core_touch_icons_form($form, $theme_name);
161
    }
162

    
163
    // Custom CSS
164
    $enable_custom_css = isset($form_state['values']['enable_custom_css']);
165
    if (($enable_custom_css && $form_state['values']['enable_custom_css'] == 1) || (!$enable_custom_css && $form['at-settings']['extend']['enable']['enable_custom_css']['#default_value'] == 1)) {
166
      require_once($path_to_at_core . '/inc/forms/settings.customcss.inc');
167
      at_core_custom_css_form($form);
168
    }
169

    
170
    // Mobile regions and blocks (context regions)
171
    $enable_context_regions = isset($form_state['values']['enable_context_regions']);
172
    if (($enable_context_regions && $form_state['values']['enable_context_regions'] == 1) || (!$enable_context_regions && $form['at-settings']['extend']['enable']['enable_context_regions']['#default_value'] == 1)) {
173
      require_once($path_to_at_core . '/inc/forms/settings.contextregions.inc');
174
      at_core_context_regions_form($form, $info_array);
175
    }
176

    
177
    // Menu toggle
178
    $enable_menu_toggle = isset($form_state['values']['enable_menu_toggle']);
179
    if (($enable_menu_toggle && $form_state['values']['enable_menu_toggle'] == 1) || (!$enable_context_regions && $form['at-settings']['extend']['enable']['enable_menu_toggle']['#default_value'] == 1)) {
180
      require_once($path_to_at_core . '/inc/forms/settings.menutoggle.inc');
181
      at_core_menu_toggle_form($form);
182
    }
183

    
184
    // Float Region blocks
185
    $enable_float_region_blocks = isset($form_state['values']['enable_float_region_blocks']);
186
    if (($enable_float_region_blocks && $form_state['values']['enable_float_region_blocks'] == 1) || (!$enable_float_region_blocks && $form['at-settings']['extend']['enable']['enable_float_region_blocks']['#default_value'] == 1)) {
187
      require_once($path_to_at_core . '/inc/forms/settings.floatregionblocks.inc');
188
      at_core_float_region_blocks_form($form, $info_array);
189
    }
190

    
191
    // Modify output
192
    $enable_markup_overides = isset($form_state['values']['enable_markup_overides']);
193
    if (($enable_markup_overides && $form_state['values']['enable_markup_overides'] == 1) || (!$enable_markup_overides && $form['at-settings']['extend']['enable']['enable_markup_overides']['#default_value'] == 1)) {
194
      require_once($path_to_at_core . '/inc/forms/settings.modifyoutput.inc');
195
      at_core_modify_output_form($form);
196
    }
197

    
198
    // Print a message if no extensions are enbabled, this is quite hard to detect
199
    // so we hack it by counting the elements in the array, if there are 4 or less
200
    // we assume no extensions are enabled.
201
    $count = count($form['at']);
202
    if ($count <= 4) {
203
      $form['at']['no_extensions_enabled'] = array(
204
        '#type' => 'markup',
205
        '#markup' => t('No extensions are currently active. Enable Extensions by clicking the Extensions tab above and checking the required extensions, then save the configuration.'),
206
        '#prefix' => '<div class="no-extensions-enabled">',
207
        '#suffix' => '</div>',
208
      );
209
    }
210
  }
211

    
212
  // Include a hidden form field with the current release information
213
  $form['at-release']['at_core'] = array(
214
    '#type' => 'hidden',
215
    '#default_value' => '7.x-3.x',
216
  );
217

    
218
  // Collapse annoying forms
219
  $form['theme_settings']['#collapsible'] = TRUE;
220
  $form['theme_settings']['#collapsed'] = TRUE;
221
  $form['logo']['#collapsible'] = TRUE;
222
  $form['logo']['#collapsed'] = TRUE;
223
  $form['favicon']['#collapsible'] = TRUE;
224
  $form['favicon']['#collapsed'] = TRUE;
225

    
226
  /**
227
   * Originally posted by dvessel (http://drupal.org/user/56782).
228
   * The following will be processed even if the theme is inactive.
229
   * If you are on a theme specific settings page but it is not an active
230
   * theme (example.com/admin/apearance/settings/THEME_NAME), it will
231
   * still be processed.
232
   *
233
   * Build a list of themes related to the theme specific form. If the form
234
   * is specific to a sub-theme, all parent themes leading to it will have
235
   * hook_form_theme_settings invoked. For example, if a theme named
236
   * 'grandchild' has its settings form in focus, the following will be invoked.
237
   * - parent_form_theme_settings()
238
   * - child_form_theme_settings()
239
   * - grandchild_form_theme_settings()
240
   *
241
   * If 'child' was in focus it will invoke:
242
   * - parent_form_theme_settings()
243
   * - child_form_theme_settings()
244
   *
245
   *  @see http://drupal.org/node/943212
246
   */
247
  $form_themes = array();
248
  $themes = list_themes();
249
  $_theme = $GLOBALS['theme_key'];
250
  while (isset($_theme)) {
251
    $form_themes[$_theme] = $_theme;
252
    $_theme = isset($themes[$_theme]->base_theme) ? $themes[$_theme]->base_theme : NULL;
253
  }
254
  $form_themes = array_reverse($form_themes);
255

    
256
  foreach ($form_themes as $theme_key) {
257
    if (function_exists($form_settings = "{$theme_key}_form_theme_settings")) {
258
      $form_settings($form, $form_state);
259
    }
260
  }
261

    
262
  // Include custom form validation and submit functions
263
  require_once(drupal_get_path('theme', 'adaptivetheme') . '/inc/forms/at_core.validate.inc');
264
  require_once(drupal_get_path('theme', 'adaptivetheme') . '/inc/forms/at_core.submit.inc');
265

    
266
  // Custom validate and submit functions
267
  $form['#validate'][] = 'at_core_settings_validate';
268
  $form['#submit'][] = 'at_core_settings_submit';
269
}