Projet

Général

Profil

Paste
Télécharger (21,5 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / themes / bootstrap / theme / settings.inc @ 87dbc3bf

1
<?php
2
/**
3
 * @file
4
 * settings.inc
5
 */
6

    
7
/**
8
 * Contains the form for the theme settings.
9
 *
10
 * @param array $form
11
 *   The form array, passed by reference.
12
 * @param array $form_state
13
 *   The form state array, passed by reference.
14
 */
15
function _bootstrap_settings_form(&$form, $form_state) {
16
  // Do not add Bootstrap specific settings to non-bootstrap based themes.
17
  $theme = !empty($form_state['build_info']['args'][0]) ? $form_state['build_info']['args'][0] : FALSE;
18
  // Global settings.
19
  if ($theme === FALSE) {
20
    return;
21
  }
22
  // Other theme settings.
23
  elseif ($theme !== 'bootstrap') {
24
    $base_theme = bootstrap_get_theme_info($theme, 'base theme');
25
    if (!$base_theme || (!is_array($base_theme) && $base_theme !== 'bootstrap') || (is_array($base_theme) && !in_array('bootstrap', $base_theme))) {
26
      return;
27
    }
28
  }
29

    
30
  // Display a warning if jquery_update isn't enabled.
31
  if ((!module_exists('jquery_update') || !version_compare(variable_get('jquery_update_jquery_version', 0), 1.7, '>=')) && !theme_get_setting('bootstrap_toggle_jquery_error')) {
32
    drupal_set_message(t('jQuery Update is not enabled, Bootstrap requires a minimum jQuery version of 1.7 or higher.<br/>Please enable <a href="https://drupal.org/project/jquery_update">jQuery Update module</a> 7.x-2.3 or higher, you must manually set this in the configuration after it is installed.'), 'error');
33
  }
34

    
35
  // Wrap global setting fieldsets in vertical tabs.
36
  $form['general'] = array(
37
    '#type' => 'vertical_tabs',
38
    '#prefix' => '<h2><small>' . t('Override Global Settings') . '</small></h2>',
39
    '#weight' => -9,
40
  );
41
  $form['theme_settings']['#group'] = 'general';
42
  $form['logo']['#group'] = 'general';
43
  $form['favicon']['#group'] = 'general';
44

    
45
  // Do not add Bootstrap specific settings to global settings.
46
  if (empty($form_state['build_info']['args'][0])) {
47
    unset($form['general']['#prefix']);
48
    return;
49
  }
50

    
51
  $form['bootstrap'] = array(
52
    '#type' => 'vertical_tabs',
53
    '#attached' => array(
54
      'js'  => array(drupal_get_path('theme', 'bootstrap') . '/js/bootstrap.admin.js'),
55
    ),
56
    '#prefix' => '<h2><small>' . t('Bootstrap Settings') . '</small></h2>',
57
    '#weight' => -10,
58
  );
59

    
60
  // Components.
61
  $form['components'] = array(
62
    '#type' => 'fieldset',
63
    '#title' => t('Components'),
64
    '#group' => 'bootstrap',
65
  );
66
  // Breadcrumbs.
67
  $form['components']['breadcrumbs'] = array(
68
    '#type' => 'fieldset',
69
    '#title' => t('Breadcrumbs'),
70
    '#collapsible' => TRUE,
71
    '#collapsed' => TRUE,
72
  );
73
  $form['components']['breadcrumbs']['bootstrap_breadcrumb'] = array(
74
    '#type' => 'select',
75
    '#title' => t('Breadcrumb visibility'),
76
    '#default_value' => theme_get_setting('bootstrap_breadcrumb'),
77
    '#options' => array(
78
      0 => t('Hidden'),
79
      1 => t('Visible'),
80
      2 => t('Only in admin areas'),
81
    ),
82
  );
83
  $form['components']['breadcrumbs']['bootstrap_breadcrumb_home'] = array(
84
    '#type' => 'checkbox',
85
    '#title' => t('Show "Home" breadcrumb link'),
86
    '#default_value' => theme_get_setting('bootstrap_breadcrumb_home'),
87
    '#description' => t('If your site has a module dedicated to handling breadcrumbs already, ensure this setting is enabled.'),
88
    '#states' => array(
89
      'invisible' => array(
90
        ':input[name="bootstrap_breadcrumb"]' => array('value' => 0),
91
      ),
92
    ),
93
  );
94
  $form['components']['breadcrumbs']['bootstrap_breadcrumb_title'] = array(
95
    '#type' => 'checkbox',
96
    '#title' => t('Show current page title at end'),
97
    '#default_value' => theme_get_setting('bootstrap_breadcrumb_title'),
98
    '#description' => t('If your site has a module dedicated to handling breadcrumbs already, ensure this setting is disabled.'),
99
    '#states' => array(
100
      'invisible' => array(
101
        ':input[name="bootstrap_breadcrumb"]' => array('value' => 0),
102
      ),
103
    ),
104
  );
105
  // Navbar.
106
  $form['components']['navbar'] = array(
107
    '#type' => 'fieldset',
108
    '#title' => t('Navbar'),
109
    '#collapsible' => TRUE,
110
    '#collapsed' => TRUE,
111
  );
112
  $form['components']['navbar']['bootstrap_navbar_position'] = array(
113
    '#type' => 'select',
114
    '#title' => t('Navbar Position'),
115
    '#description' => t('Select your Navbar position.'),
116
    '#default_value' => theme_get_setting('bootstrap_navbar_position'),
117
    '#options' => array(
118
      'static-top' => t('Static Top'),
119
      'fixed-top' => t('Fixed Top'),
120
      'fixed-bottom' => t('Fixed Bottom'),
121
    ),
122
    '#empty_option' => t('Normal'),
123
  );
124
  $form['components']['navbar']['bootstrap_navbar_inverse'] = array(
125
    '#type' => 'checkbox',
126
    '#title' => t('Inverse navbar style'),
127
    '#description' => t('Select if you want the inverse navbar style.'),
128
    '#default_value' => theme_get_setting('bootstrap_navbar_inverse'),
129
  );
130

    
131
  // Region wells.
132
  $wells = array(
133
    '' => t('None'),
134
    'well' => t('.well (normal)'),
135
    'well well-sm' => t('.well-sm (small)'),
136
    'well well-lg' => t('.well-lg (large)'),
137
  );
138
  $form['components']['region_wells'] = array(
139
    '#type' => 'fieldset',
140
    '#title' => t('Region wells'),
141
    '#description' => t('Enable the <code>.well</code>, <code>.well-sm</code> or <code>.well-lg</code> classes for specified regions. See: documentation on !wells.', array(
142
      '!wells' => l(t('Bootstrap Wells'), 'http://getbootstrap.com/components/#wells'),
143
    )),
144
    '#collapsible' => TRUE,
145
    '#collapsed' => TRUE,
146
  );
147
  foreach (system_region_list($theme) as $name => $title) {
148
    $form['components']['region_wells']['bootstrap_region_well-' . $name] = array(
149
      '#title' => $title,
150
      '#type' => 'select',
151
      '#attributes' => array(
152
        'class' => array('input-sm'),
153
      ),
154
      '#options' => $wells,
155
      '#default_value' => theme_get_setting('bootstrap_region_well-' . $name),
156
    );
157
  }
158

    
159
  // JavaScript settings.
160
  $form['javascript'] = array(
161
    '#type' => 'fieldset',
162
    '#title' => t('JavaScript'),
163
    '#group' => 'bootstrap',
164
  );
165
  // Anchors.
166
  $form['javascript']['anchors'] = array(
167
    '#type' => 'fieldset',
168
    '#title' => t('Anchors'),
169
    '#collapsible' => TRUE,
170
    '#collapsed' => TRUE,
171
  );
172
  $form['javascript']['anchors']['bootstrap_anchors_fix'] = array(
173
    '#type' => 'checkbox',
174
    '#title' => t('Fix anchor positions'),
175
    '#default_value' => theme_get_setting('bootstrap_anchors_fix'),
176
    '#description' => t('Ensures anchors are correctly positioned only when there is margin or padding detected on the BODY element. This is useful when fixed navbar or administration menus are used.'),
177
  );
178
  $form['javascript']['anchors']['bootstrap_anchors_smooth_scrolling'] = array(
179
    '#type' => 'checkbox',
180
    '#title' => t('Enable smooth scrolling'),
181
    '#default_value' => theme_get_setting('bootstrap_anchors_smooth_scrolling'),
182
    '#description' => t('Animates page by scrolling to an anchor link target smoothly when clicked.'),
183
    '#states' => array(
184
      'invisible' => array(
185
        ':input[name="bootstrap_anchors_fix"]' => array('checked' => FALSE),
186
      ),
187
    ),
188
  );
189
  // Popovers.
190
  $form['javascript']['popovers'] = array(
191
    '#type' => 'fieldset',
192
    '#title' => t('Popovers'),
193
    '#description' => t('Add small overlays of content, like those on the iPad, to any element for housing secondary information.'),
194
    '#collapsible' => TRUE,
195
    '#collapsed' => TRUE,
196
  );
197
  $form['javascript']['popovers']['bootstrap_popover_enabled'] = array(
198
    '#type' => 'checkbox',
199
    '#title' => t('Enable popovers.'),
200
    '#description' => t('Elements that have the !code attribute set will automatically initialize the popover upon page load. !warning', array(
201
      '!code' => '<code>data-toggle="popover"</code>',
202
      '!warning' => '<strong class="error text-error">WARNING: This feature can sometimes impact performance. Disable if pages appear to "hang" after initial load.</strong>',
203
    )),
204
    '#default_value' => theme_get_setting('bootstrap_popover_enabled'),
205
  );
206
  $form['javascript']['popovers']['options'] = array(
207
    '#type' => 'fieldset',
208
    '#title' => t('Options'),
209
    '#description' => t('These are global options. Each popover can independently override desired settings by appending the option name to !data. Example: !data-animation.', array(
210
      '!data' => '<code>data-</code>',
211
      '!data-animation' => '<code>data-animation="false"</code>',
212
    )),
213
    '#collapsible' => TRUE,
214
    '#collapsed' => TRUE,
215
    '#states' => array(
216
      'visible' => array(
217
        ':input[name="bootstrap_popover_enabled"]' => array('checked' => TRUE),
218
      ),
219
    ),
220
  );
221
  $form['javascript']['popovers']['options']['bootstrap_popover_animation'] = array(
222
    '#type' => 'checkbox',
223
    '#title' => t('animate'),
224
    '#description' => t('Apply a CSS fade transition to the popover.'),
225
    '#default_value' => theme_get_setting('bootstrap_popover_animation'),
226
  );
227
  $form['javascript']['popovers']['options']['bootstrap_popover_html'] = array(
228
    '#type' => 'checkbox',
229
    '#title' => t('HTML'),
230
    '#description' => t("Insert HTML into the popover. If false, jQuery's text method will be used to insert content into the DOM. Use text if you're worried about XSS attacks."),
231
    '#default_value' => theme_get_setting('bootstrap_popover_html'),
232
  );
233
  $form['javascript']['popovers']['options']['bootstrap_popover_placement'] = array(
234
    '#type' => 'select',
235
    '#title' => t('placement'),
236
    '#description' => t('Where to position the popover. When "auto" is specified, it will dynamically reorient the popover. For example, if placement is "auto left", the popover will display to the left when possible, otherwise it will display right.'),
237
    '#default_value' => theme_get_setting('bootstrap_popover_placement'),
238
    '#options' => drupal_map_assoc(array(
239
      'top',
240
      'bottom',
241
      'left',
242
      'right',
243
      'auto',
244
      'auto top',
245
      'auto bottom',
246
      'auto left',
247
      'auto right',
248
    )),
249
  );
250
  $form['javascript']['popovers']['options']['bootstrap_popover_selector'] = array(
251
    '#type' => 'textfield',
252
    '#title' => t('selector'),
253
    '#description' => t('If a selector is provided, tooltip objects will be delegated to the specified targets. In practice, this is used to enable dynamic HTML content to have popovers added. See !this and !example.', array(
254
      '!this' => l(t('this'), 'https://github.com/twbs/bootstrap/issues/4215'),
255
      '!example' => l(t('an informative example'), 'http://jsfiddle.net/fScua/'),
256
    )),
257
    '#default_value' => theme_get_setting('bootstrap_popover_selector'),
258
  );
259
  $form['javascript']['popovers']['options']['bootstrap_popover_trigger'] = array(
260
    '#type' => 'checkboxes',
261
    '#title' => t('trigger'),
262
    '#description' => t('How a popover is triggered.'),
263
    '#default_value' => theme_get_setting('bootstrap_popover_trigger'),
264
    '#options' => drupal_map_assoc(array(
265
      'click',
266
      'hover',
267
      'focus',
268
      'manual',
269
    )),
270
  );
271
  $form['javascript']['popovers']['options']['bootstrap_popover_title'] = array(
272
    '#type' => 'textfield',
273
    '#title' => t('title'),
274
    '#description' => t("Default title value if \"title\" attribute isn't present."),
275
    '#default_value' => theme_get_setting('bootstrap_popover_title'),
276
  );
277
  $form['javascript']['popovers']['options']['bootstrap_popover_content'] = array(
278
    '#type' => 'textfield',
279
    '#title' => t('content'),
280
    '#description' => t("Default content value if \"data-content\" attribute isn't present."),
281
    '#default_value' => theme_get_setting('bootstrap_popover_content'),
282
  );
283
  $form['javascript']['popovers']['options']['bootstrap_popover_delay'] = array(
284
    '#type' => 'textfield',
285
    '#title' => t('delay'),
286
    '#description' => t('The amount of time to delay showing and hiding the popover (in milliseconds). Does not apply to manual trigger type.'),
287
    '#default_value' => theme_get_setting('bootstrap_popover_delay'),
288
  );
289
  $form['javascript']['popovers']['options']['bootstrap_popover_container'] = array(
290
    '#type' => 'textfield',
291
    '#title' => t('container'),
292
    '#description' => t('Appends the popover to a specific element. Example: "body". This option is particularly useful in that it allows you to position the popover in the flow of the document near the triggering element - which will prevent the popover from floating away from the triggering element during a window resize.'),
293
    '#default_value' => theme_get_setting('bootstrap_popover_container'),
294
  );
295
  // Tooltips.
296
  $form['javascript']['tooltips'] = array(
297
    '#type' => 'fieldset',
298
    '#title' => t('Tooltips'),
299
    '#description' => t("Inspired by the excellent jQuery.tipsy plugin written by Jason Frame; Tooltips are an updated version, which don't rely on images, use CSS3 for animations, and data-attributes for local title storage. See !link for more documentation.", array(
300
      '!link' => l(t('Bootstrap tooltips'), 'http://getbootstrap.com/javascript/#tooltips'),
301
    )),
302
    '#collapsible' => TRUE,
303
    '#collapsed' => TRUE,
304
  );
305
  $form['javascript']['tooltips']['bootstrap_tooltip_enabled'] = array(
306
    '#type' => 'checkbox',
307
    '#title' => t('Enable tooltips'),
308
    '#description' => t('Elements that have the !code attribute set will automatically initialize the tooltip upon page load. !warning', array(
309
      '!code' => '<code>data-toggle="tooltip"</code>',
310
      '!warning' => '<strong class="error text-error">WARNING: This feature can sometimes impact performance. Disable if pages appear to "hang" after initial load.</strong>',
311
    )),
312
    '#default_value' => theme_get_setting('bootstrap_tooltip_enabled'),
313
  );
314
  $form['javascript']['tooltips']['bootstrap_tooltip_descriptions'] = array(
315
    '#type' => 'checkbox',
316
    '#title' => t('Convert simple form descriptions'),
317
    '#description' => t('Form items that contain simple descriptions (no HTML and shorter than 200 characters) will be converted into tooltips. This helps reduce the sometimes unnecessary noise of form item descriptions. By treating descriptions that contain longer text or HTML as actionable descriptions, we ensure it is always visible so its usability remains intact.'),
318
    '#default_value' => theme_get_setting('bootstrap_tooltip_descriptions'),
319
    '#states' => array(
320
      'visible' => array(
321
        ':input[name="bootstrap_tooltip_enabled"]' => array('checked' => TRUE),
322
      ),
323
    ),
324
  );
325
  $form['javascript']['tooltips']['options'] = array(
326
    '#type' => 'fieldset',
327
    '#title' => t('Options'),
328
    '#description' => t('These are global options. Each tooltip can independently override desired settings by appending the option name to !data. Example: !data-animation.', array(
329
      '!data' => '<code>data-</code>',
330
      '!data-animation' => '<code>data-animation="false"</code>',
331
    )),
332
    '#collapsible' => TRUE,
333
    '#collapsed' => TRUE,
334
    '#states' => array(
335
      'visible' => array(
336
        ':input[name="bootstrap_tooltip_enabled"]' => array('checked' => TRUE),
337
      ),
338
    ),
339
  );
340
  $form['javascript']['tooltips']['options']['bootstrap_tooltip_animation'] = array(
341
    '#type' => 'checkbox',
342
    '#title' => t('animate'),
343
    '#description' => t('Apply a CSS fade transition to the tooltip.'),
344
    '#default_value' => theme_get_setting('bootstrap_tooltip_animation'),
345
  );
346
  $form['javascript']['tooltips']['options']['bootstrap_tooltip_html'] = array(
347
    '#type' => 'checkbox',
348
    '#title' => t('HTML'),
349
    '#description' => t("Insert HTML into the tooltip. If false, jQuery's text method will be used to insert content into the DOM. Use text if you're worried about XSS attacks."),
350
    '#default_value' => theme_get_setting('bootstrap_tooltip_html'),
351
  );
352
  $form['javascript']['tooltips']['options']['bootstrap_tooltip_placement'] = array(
353
    '#type' => 'select',
354
    '#title' => t('placement'),
355
    '#description' => t('Where to position the tooltip. When "auto" is specified, it will dynamically reorient the tooltip. For example, if placement is "auto left", the tooltip will display to the left when possible, otherwise it will display right.'),
356
    '#default_value' => theme_get_setting('bootstrap_tooltip_placement'),
357
    '#options' => drupal_map_assoc(array(
358
      'top',
359
      'bottom',
360
      'left',
361
      'right',
362
      'auto',
363
      'auto top',
364
      'auto bottom',
365
      'auto left',
366
      'auto right',
367
    )),
368
  );
369
  $form['javascript']['tooltips']['options']['bootstrap_tooltip_selector'] = array(
370
    '#type' => 'textfield',
371
    '#title' => t('selector'),
372
    '#description' => t('If a selector is provided, tooltip objects will be delegated to the specified targets.'),
373
    '#default_value' => theme_get_setting('bootstrap_tooltip_selector'),
374
  );
375
  $form['javascript']['tooltips']['options']['bootstrap_tooltip_trigger'] = array(
376
    '#type' => 'checkboxes',
377
    '#title' => t('trigger'),
378
    '#description' => t('How a tooltip is triggered.'),
379
    '#default_value' => theme_get_setting('bootstrap_tooltip_trigger'),
380
    '#options' => drupal_map_assoc(array(
381
      'click',
382
      'hover',
383
      'focus',
384
      'manual',
385
    )),
386
  );
387
  $form['javascript']['tooltips']['options']['bootstrap_tooltip_delay'] = array(
388
    '#type' => 'textfield',
389
    '#title' => t('delay'),
390
    '#description' => t('The amount of time to delay showing and hiding the tooltip (in milliseconds). Does not apply to manual trigger type.'),
391
    '#default_value' => theme_get_setting('bootstrap_tooltip_delay'),
392
  );
393
  $form['javascript']['tooltips']['options']['bootstrap_tooltip_container'] = array(
394
    '#type' => 'textfield',
395
    '#title' => t('container'),
396
    '#description' => t('Appends the tooltip to a specific element. Example: "body"'),
397
    '#default_value' => theme_get_setting('bootstrap_tooltip_container'),
398
  );
399

    
400
  // Advanced settings.
401
  $form['advanced'] = array(
402
    '#type' => 'fieldset',
403
    '#title' => t('Advanced'),
404
    '#group' => 'bootstrap',
405
  );
406
  // BootstrapCDN.
407
  $form['advanced']['bootstrap_cdn'] = array(
408
    '#type' => 'fieldset',
409
    '#title' => t('BootstrapCDN'),
410
    '#description' => t('Use !bootstrapcdn to serve the Bootstrap framework files. Enabling this setting will prevent this theme from attempting to load any Bootstrap framework files locally. !warning', array(
411
      '!bootstrapcdn' => l(t('BootstrapCDN'), 'http://bootstrapcdn.com', array(
412
        'external' => TRUE,
413
      )),
414
      '!warning' => '<div class="alert alert-info messages info"><strong>' . t('NOTE') . ':</strong> ' . t('While BootstrapCDN (content distribution network) is the preferred method for providing huge performance gains in load time, this method does depend on using this third party service. BootstrapCDN is under no obligation or commitment to provide guaranteed up-time or service quality for this theme. If you choose to disable this setting, you must provide your own Bootstrap source and/or optional CDN delivery implementation.') . '</div>',
415
    )),
416
    '#collapsible' => TRUE,
417
    '#collapsed' => TRUE,
418
  );
419
  $form['advanced']['bootstrap_cdn']['bootstrap_cdn'] = array(
420
    '#type' => 'select',
421
    '#title' => t('BootstrapCDN version'),
422
    '#options' => drupal_map_assoc(array(
423
      '3.0.0',
424
      '3.0.1',
425
      '3.0.2',
426
    )),
427
    '#default_value' => theme_get_setting('bootstrap_cdn'),
428
    '#empty_option' => t('Disabled'),
429
    '#empty_value' => NULL,
430
  );
431
  // Bootswatch.
432
  $bootswatch_themes = array();
433
  $request = drupal_http_request('http://api.bootswatch.com/3/');
434
  if ($request && $request->code === '200' && !empty($request->data)) {
435
    if (($api = drupal_json_decode($request->data)) && is_array($api) && !empty($api['themes'])) {
436
      foreach ($api['themes'] as $bootswatch_theme) {
437
        $bootswatch_themes[strtolower($bootswatch_theme['name'])] = $bootswatch_theme['name'];
438
      }
439
    }
440
  }
441
  $form['advanced']['bootstrap_cdn']['bootstrap_bootswatch'] = array(
442
    '#type' => 'select',
443
    '#title' => t('Bootswatch theme'),
444
    '#description' => t('Use !bootstrapcdn to serve a Bootswatch Theme. Choose Bootswatch theme here.', array(
445
      '!bootstrapcdn' => l(t('BootstrapCDN'), 'http://bootstrapcdn.com', array(
446
        'external' => TRUE,
447
      )),
448
    )),
449
    '#default_value' => theme_get_setting('bootstrap_bootswatch'),
450
    '#options' => $bootswatch_themes,
451
    '#empty_option' => t('Disabled'),
452
    '#empty_value' => NULL,
453
    '#suffix' => '<div id="bootswatch-preview"></div>',
454
    '#states' => array(
455
      'invisible' => array(
456
        ':input[name="bootstrap_cdn"]' => array('value' => ''),
457
      ),
458
    ),
459
  );
460
  if (empty($bootswatch_themes)) {
461
    $form['advanced']['bootstrap_cdn']['bootstrap_bootswatch']['#prefix'] = '<div class="alert alert-danger messages error"><strong>' . t('ERROR') . ':</strong> ' . t('Unable to reach Bootswatch API. Please ensure the server your website is hosted on is able to initiate HTTP requests.') . '</div>';
462
  }
463
  // Rebuild registry.
464
  $form['advanced']['bootstrap_rebuild_registry'] = array(
465
    '#type' => 'checkbox',
466
    '#title' => t('Rebuild theme registry on every page.'),
467
    '#default_value' => theme_get_setting('bootstrap_rebuild_registry'),
468
    '#description' => t('During theme development, it can be very useful to continuously !rebuild. !warning', array(
469
      '!rebuild' => l(t('rebuild the theme registry'), 'http://drupal.org/node/173880#theme-registry'),
470
      '!warning' => '<div class="alert alert-warning messages warning"><strong>' . t('WARNING') . ':</strong> ' . t('This is a huge performance penalty and must be turned off on production websites. ') . '</div>',
471
    )),
472
  );
473
  // Suppress jQuery message.
474
  $form['advanced']['bootstrap_toggle_jquery_error'] = array(
475
    '#type' => 'checkbox',
476
    '#title' => t('Suppress jQuery version error message'),
477
    '#default_value' => theme_get_setting('bootstrap_toggle_jquery_error'),
478
    '#description' => t('Enable this if the version of jQuery has been upgraded to 1.7+ using a method other than the !jquery_update module.', array(
479
      '!jquery_update' => l(t('jQuery Update'), 'https://drupal.org/project/jquery_update'),
480
    )),
481
  );
482

    
483
}