Projet

Général

Profil

Paste
Télécharger (23 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / flexslider / flexslider.admin.inc @ a45e4bc1

1
<?php
2
/**
3
 * @file
4
 * Administrative page callbacks for the flexslider module.
5
 */
6

    
7
/**
8
 * Submit handler for adding a new option set.
9
 */
10
function flexslider_form_optionset_add_submit($form, &$form_state) {
11
  $optionset = flexslider_optionset_create(array('name' => $form_state['values']['name'], 'title' => $form_state['values']['title']));
12

    
13
  $saved = flexslider_optionset_save($optionset, TRUE);
14

    
15
  if ($saved) {
16
    drupal_set_message(t('Option set %name was created.', array('%name' => $optionset->name)));
17
    $form_state['redirect'] = 'admin/config/media/flexslider/edit/' . $optionset->name;
18
  }
19
  else {
20
    drupal_set_message(t('Failed to create option set. Please verify your settings.'), 'error');
21
  }
22
}
23

    
24
/**
25
 * Defines the form elements used to edit the FlexSlider library options
26
 *
27
 * @param array $options [optional]
28
 *  Pass in a set of default values for the options
29
 * @return array
30
 *  Returns the option set array
31
 */
32
function flexslider_option_elements($options = array()) {
33
  $form = array();
34

    
35
  // General Slideshow and Animiation Settings
36
  $form['animation_slideshow'] = array(
37
    '#type' => 'fieldset',
38
    '#title' => t('General Slideshow and Animation Settings'),
39
  );
40

    
41
  $form['animation_slideshow']['animation'] = array(
42
    '#type' => 'select',
43
    '#title' => t('Animation'),
44
    '#description' => t('Select your animation type'),
45
    '#options' => array(
46
      'fade'   => t('Fade'),
47
      'slide'  => t('Slide'),
48
    ),
49
    '#default_value' => isset($options['animation']) ? $options['animation'] : _flexslider_optionset_defaults('animation'),
50
    // @todo add states to enable/disable the direction
51
  );
52

    
53
  $form['animation_slideshow']['animationSpeed'] = array(
54
    '#type' => 'textfield',
55
    '#title' => t('Animation Speed'),
56
    '#description' => t('Set the speed of animations, in milliseconds'),
57
    '#element_validate' => array('_flexslider_validate_positive_integer'),
58
    '#default_value' => isset($options['animationSpeed']) ? $options['animationSpeed'] : _flexslider_optionset_defaults('animationSpeed'),
59
    '#size' => 30,
60
  );
61

    
62
  $form['animation_slideshow']['direction'] = array(
63
    '#type' => 'select',
64
    '#title' => t('Slide Direction'),
65
    '#description' => t('Select the sliding direction, "horizontal" or "vertical"'),
66
    '#options' => array(
67
      'horizontal'   => t('Horizontal'),
68
      'vertical'  => t('Vertical'),
69
    ),
70
    '#default_value' =>  isset($options['direction']) ? $options['direction'] : _flexslider_optionset_defaults('direction'),
71
  );
72

    
73
  $form['animation_slideshow']['slideshow'] = array(
74
    '#type' => 'checkbox',
75
    '#title' => t('Slideshow'),
76
    '#description' => t('Animate the slides automatically'),
77
    '#default_value' => isset($options['slideshow']) ? $options['slideshow'] : _flexslider_optionset_defaults('slideshow'),
78
  );
79

    
80
  // Build in support for easing plugin
81
  $easing_options = array('swing' => t('Swing'), 'linear' => t('Linear'));
82
  if (module_exists('jqeasing')) {
83
    $easing_options = array_merge($easing_options, _flexslider_jqeasing_options());
84
    
85
  }
86

    
87
  $form['animation_slideshow']['easing'] = array(
88
    '#type' => 'select',
89
    '#title' => t('Easing'),
90
    '#multiple' => FALSE,
91
    '#description' => t('The description appears usually below the item.'),
92
    '#options' => $easing_options,
93
    '#default_value' => isset($options['easing']) ? $options['easing'] : _flexslider_optionset_defaults('easing'),
94
  );
95

    
96
  $form['animation_slideshow']['smoothHeight'] = array(
97
    '#type' => 'checkbox',
98
    '#title' => t('Smooth Height'),
99
    '#description' => t('Animate the height of the slider smoothly for slides of varying height.'),
100
    '#default_value' => isset($options['smoothHeight']) ? $options['smoothHeight'] : _flexslider_optionset_defaults('smoothHeight'),
101
  );
102

    
103
  $form['animation_slideshow']['reverse'] = array(
104
    '#type' => 'checkbox',
105
    '#title' => t('Reverse'),
106
    '#description' => t('Animate the slides in reverse'),
107
    '#default_value' => isset($options['reverse']) ? $options['reverse'] : _flexslider_optionset_defaults('reverse'),
108
  );
109

    
110
  $form['animation_slideshow']['slideshowSpeed'] = array(
111
    '#type' => 'textfield',
112
    '#title' => t('Slideshow speed'),
113
    '#description' => t('Set the speed of the slideshow cycling, in milliseconds'),
114
    '#element_validate' => array('_flexslider_validate_positive_integer'),
115
    '#default_value' => isset($options['slideshowSpeed']) ? $options['slideshowSpeed'] : _flexslider_optionset_defaults('slideshowSpeed'),
116
    '#size' => 30,
117
  );
118

    
119
  $form['animation_slideshow']['animationLoop'] = array(
120
    '#type' => 'checkbox',
121
    '#title' => t('Loop Slideshow'),
122
    '#description' => t('Loop the slideshow once it reaches the last slide.'),
123
    '#default_value' => isset($options['animationLoop']) ? $options['animationLoop'] : _flexslider_optionset_defaults('animationLoop'),
124
  );
125

    
126
  $form['animation_slideshow']['randomize'] = array(
127
    '#type' => 'checkbox',
128
    '#title' => t('Randomize Slide Order'),
129
    '#description' => t('Randomize the order the slides play back.'),
130
    '#default_value' => isset($options['randomize']) ? $options['randomize'] : _flexslider_optionset_defaults('randomize'),
131
  );
132
  $form['animation_slideshow']['startAt'] = array(
133
    '#type' => 'textfield',
134
    '#title' => t('Starting Slide'),
135
    '#description' => t('The slide that the slider should start on. Ex: For the first slide enter "0", for the second enter "1", etc. If you enter a value which is greater than the number of slides, the slider will default to the first slide.'),
136
    '#element_validate' => array('_flexslider_validate_positive_integer'),
137
    '#default_value' => isset($options['startAt']) ? $options['startAt'] : _flexslider_optionset_defaults('startAt'),
138
    '#size' => 30,
139
    // @todo add states to disable if randomize is set
140
  );
141

    
142
  $form['animation_slideshow']['itemWidth'] = array(
143
    '#type' => 'textfield',
144
    '#title' => t('Item Width'),
145
    '#description' => t('Box-model width of individual carousel items, including horizontal borders and padding.'),
146
    '#size' => 40,
147
    '#maxlength' => 255,
148
    '#default_value' => isset($options['itemWidth']) ? $options['itemWidth'] : _flexslider_optionset_defaults('itemWidth'),
149
  );
150
  $form['animation_slideshow']['itemMargin'] = array(
151
    '#type' => 'textfield',
152
    '#title' => t('Item Margin'),
153
    '#description' => t('Margin between carousel items. (NB: the margin must be set in your CSS styles. This property merely informs FlexSlider of the margin.)'),
154
    '#size' => 40,
155
    '#maxlength' => 255,
156
    '#default_value' => isset($options['itemMargin']) ? $options['itemMargin'] : _flexslider_optionset_defaults('itemMargin'),
157
  );
158
  $form['animation_slideshow']['minItems'] = array(
159
    '#type' => 'textfield',
160
    '#title' => t('Minimum Items'),
161
    '#description' => t('Minimum number of carousel items that should be visible.'),
162
    '#size' => 40,
163
    '#maxlength' => 255,
164
    '#default_value' => isset($options['minItems']) ? $options['minItems'] : _flexslider_optionset_defaults('minItems'),
165
  );
166
  $form['animation_slideshow']['maxItems'] = array(
167
    '#type' => 'textfield',
168
    '#title' => t('Max Items'),
169
    '#description' => t('Maximum number of carousel items that should be visible.'),
170
    '#size' => 40,
171
    '#maxlength' => 255,
172
    '#default_value' => isset($options['maxItems']) ? $options['maxItems'] : _flexslider_optionset_defaults('maxItems'),
173
  );
174
  $form['animation_slideshow']['move'] = array(
175
    '#type' => 'textfield',
176
    '#title' => t('Move'),
177
    '#description' => t('Number of carousel items that should move on animation. If 0, slider will move all visible items.'),
178
    '#size' => 40,
179
    '#maxlength' => 255,
180
    '#default_value' => isset($options['move']) ? $options['move'] : _flexslider_optionset_defaults('move'),
181
  );
182

    
183
  // Navigation and Control Settings
184
  $form['nav_controls'] = array(
185
    '#type' => 'fieldset',
186
    '#title' => t('Navigation and Control Settings'),
187
  );
188
  $form['nav_controls']['directionNav'] = array(
189
    '#type' => 'checkbox',
190
    '#title' => t('Next/Previous Controls'),
191
    '#description' => t('Add controls for previous/next navigation'),
192
    '#default_value' => isset($options['directionNav']) ? $options['directionNav'] : _flexslider_optionset_defaults('directionNav'),
193
  );
194
  $form['nav_controls']['controlNav'] = array(
195
    '#type' => 'select',
196
    '#title' => t('Paging Controls'),
197
    '#description' => t('Add controls to jump to individual slides. (Note: set to "On" if using Manual Controls)'),
198
    '#default_value' => isset($options['controlNav']) ? $options['controlNav'] : _flexslider_optionset_defaults('controlNav'),
199
    '#options' => array(
200
      0 => t('Off'),
201
      1 => t('On'),
202
      'thumbnails' => t('Thumbnails'),
203
    )
204
  );
205
  $form['nav_controls']['thumbCaptions'] = array(
206
    '#type' => 'checkbox',
207
    '#title' => t('Thumbnail Captions'),
208
    '#description' => t('<em>Requires FlexSlider Library 2.2+</em>. After selecting this captions will be added to thumbnails and removed from the main slide.'),
209
    '#default_value' => isset($options['thumbCaptions']) ? $options['thumbCaptions'] : _flexslider_optionset_defaults('thumbCaptions'),
210
    '#states' => array(
211
      'visible' => array(
212
        ':input[name="controlNav"]' => array('value' => 'thumbnails'),
213
      ),
214
    ),
215
    '#element_validate' => array('_flexslider_validate_minimum_version_22'),
216
  );
217
  $form['nav_controls']['thumbCaptionsBoth'] = array(
218
    '#type' => 'checkbox',
219
    '#title' => t('Display both thumbnail captions and normal captions'),
220
    '#description' => t('<em>Requires FlexSlider Library 2.2+</em>. Display captions in the thumbnail as well as in the slider.'),
221
    '#default_value' => isset($options['thumbCaptionsBoth']) ? $options['thumbCaptionsBoth'] : _flexslider_optionset_defaults('thumbCaptionsBoth'),
222
    '#states' => array(
223
      'visible' => array(
224
        ':input[name="controlNav"]' => array('value' => 'thumbnails'),
225
      ),
226
    ),
227
    '#element_validate' => array('_flexslider_validate_minimum_version_22'),
228
  );
229
  $form['nav_controls']['keyboard'] = array(
230
    '#type' => 'checkbox',
231
    '#title' => t('Keyboard Navigation'),
232
    '#description' => t('Allow slider navigating via keyboard left/right keys'),
233
    '#default_value' => isset($options['keyboard']) ? $options['keyboard'] : _flexslider_optionset_defaults('keyboard'),
234
  );
235
  $form['nav_controls']['multipleKeyboard'] = array(
236
    '#type' => 'checkbox',
237
    '#title' => t('Multiple Keyboard'),
238
    '#description' => t('Allow keyboard navigation to affect multiple sliders.'),
239
    '#default_value' => isset($options['multipleKeyboard']) ? $options['multipleKeyboard'] : _flexslider_optionset_defaults('multipleKeyboard'),
240
  );
241
  $form['nav_controls']['mousewheel'] = array(
242
    '#type' => 'checkbox',
243
    '#title' => t('Mousewheel Navigation'),
244
    '#description' => t('Allow slider navigating via mousewheel'),
245
    '#default_value' => isset($options['mousewheel']) ? $options['mousewheel'] : _flexslider_optionset_defaults('mousewheel'),
246
    // @todo add check for jquery mousewheel library
247
  );
248
  $form['nav_controls']['touch'] = array(
249
    '#type' => 'checkbox',
250
    '#title' => t('Touch'),
251
    '#description' => t('Allow touch swipe navigation.'),
252
    '#default_value' => isset($options['touch']) ? $options['touch'] : _flexslider_optionset_defaults('touch'),
253
  );
254
  $form['nav_controls']['prevText'] = array(
255
    '#type' => 'textfield',
256
    '#title' => t('Previous Link Text'),
257
    '#description' => t('Set the text for the "previous" control item. <em>Text translation can be controlled using the <a href="http://drupal.org/project/stringoverrides">String Overrides module</a>.</em>'),
258
    '#default_value' => isset($options['prevText']) ? $options['prevText'] : _flexslider_optionset_defaults('prevText'),
259
  );
260
  $form['nav_controls']['nextText'] = array(
261
    '#type' => 'textfield',
262
    '#title' => t('Next Link Text'),
263
    '#description' => t('Set the text for the "next" control item. <em>Text translation can be controlled using the <a href="http://drupal.org/project/stringoverrides">String Overrides module</a>.</em>'),
264
    '#default_value' => isset($options['nextText']) ? $options['nextText'] : _flexslider_optionset_defaults('nextText'),
265
  );
266

    
267
  // Advanced Options
268
  $form['advanced'] = array(
269
    '#type' => 'fieldset',
270
    '#title' => t('Advanced Options'),
271
  );
272
  $form['advanced']['namespace'] = array(
273
    '#type' => 'textfield',
274
    '#title' => t('Namespace'),
275
    '#description' => t('Prefix string attached to the classes of all elements generated by the plugin.'),
276
    '#size' => 40,
277
    '#maxlength' => 255,
278
    '#element_validate' => array('_flexslider_validate_namespace'),
279
    '#default_value' => isset($options['namespace']) ? $options['namespace'] : _flexslider_optionset_defaults('namespace'),
280
  );
281
  $form['advanced']['selector'] = array(
282
    '#type' => 'textfield',
283
    '#title' => t('Selector'),
284
    '#description' => t('Must match a simple pattern. "{container} > {slide}".'),
285
    '#size' => 40,
286
    '#maxlength' => 255,
287
    '#element_validate' => array('_flexslider_validate_selector'),
288
    '#default_value' => isset($options['selector']) ? $options['selector'] : _flexslider_optionset_defaults('selector'),
289
  );
290
  $form['advanced']['sync'] = array(
291
    '#type' => 'textfield',
292
    '#title' => t('Sync'),
293
    '#description' => t('Mirror the actions performed on this slider with another slider.'),
294
    '#size' => 40,
295
    '#maxlength' => 255,
296
    '#default_value' => isset($options['sync']) ? $options['sync'] : _flexslider_optionset_defaults('sync'),
297
  );
298
  $form['advanced']['asNavFor'] = array(
299
    '#type' => 'textfield',
300
    '#title' => t('Use as navigation'),
301
    '#description' => t('Turn the slider into a thumbnail navigation for another slider.'),
302
    '#size' => 40,
303
    '#maxlength' => 255,
304
    '#default_value' => isset($options['asNavFor']) ? $options['asNavFor'] : _flexslider_optionset_defaults('asNavFor'),
305
  );
306

    
307
  $form['advanced']['initDelay'] =  array(
308
    '#type' => 'textfield',
309
    '#title' => t('Initialize Delay'),
310
    '#description' => t('Set an initialization delay, in milliseconds.'),
311
    '#size' => 20,
312
    '#maxlength' => 255,
313
    '#default_value' => isset($options['initDelay']) ? $options['initDelay'] : _flexslider_optionset_defaults('initDelay'),
314
    //'#element_validate' => add validate on zero or greater integer
315
  );
316
  $form['advanced']['useCSS'] = array(
317
    '#type' => 'checkbox',
318
    '#title' => t('Use CSS'),
319
    '#description' => t('Slider will use CSS3 transitions, if available.'),
320
    '#default_value' => isset($options['useCSS']) ? $options['useCSS'] : _flexslider_optionset_defaults('useCSS'),
321
  );
322
  $form['advanced']['video'] = array(
323
    '#type' => 'checkbox',
324
    '#title' => t('Video'),
325
    '#description' => t('Will prevent use of CSS3 3D Transforms, avoiding graphical glitches.'),
326
    '#default_value' => isset($options['video']) ? $options['video'] : _flexslider_optionset_defaults('video'),
327
  );
328
  $form['advanced']['pausePlay'] = array(
329
    '#type' => 'checkbox',
330
    '#title' => t('Add Pause/Play Indicator'),
331
    '#description' => t('Have FlexSlider add an element indicating the current state of the slideshow (i.e. "pause" or "play").'),
332
    '#default_value' => isset($options['pausePlay']) ? $options['pausePlay'] : _flexslider_optionset_defaults('pausePlay'),
333
    // @todo add states value for pause/play text
334
  );
335
  $form['advanced']['pauseText'] = array(
336
    '#type' => 'textfield',
337
    '#title' => t('Pause State Text'),
338
    '#description' => t('Set the text for the "pause" state indicator. <em>Text translation can be controlled using the <a href="http://drupal.org/project/stringoverrides">String Overrides module</a>.</em>'),
339
    '#default_value' => isset($options['pauseText']) ? $options['pauseText'] : _flexslider_optionset_defaults('pauseText'),
340
  );
341
  $form['advanced']['playText'] = array(
342
    '#type' => 'textfield',
343
    '#title' => t('Play State Text'),
344
    '#description' => t('Set the text for the "play" state indicator. <em>Text translation can be controlled using the <a href="http://drupal.org/project/stringoverrides">String Overrides module</a>.</em>'),
345
    '#default_value' => isset($options['playText']) ? $options['playText'] : _flexslider_optionset_defaults('playText'),
346
  );
347
  $form['advanced']['pauseOnAction'] = array(
348
    '#type' => 'checkbox',
349
    '#title' => t('Pause On Controls'),
350
    '#description' => t('Pause the slideshow when interacting with control elements.'),
351
    '#default_value' => isset($options['pauseOnAction']) ? $options['pauseOnAction'] : _flexslider_optionset_defaults('pauseOnAction'),
352
  );
353
  $form['advanced']['pauseOnHover'] = array(
354
    '#type' => 'checkbox',
355
    '#title' => t('Pause On Hover'),
356
    '#description' => t('Pause the slideshow when hovering over slider, then resume when no longer hovering.'),
357
    '#default_value' => isset($options['pauseOnHover']) ? $options['pauseOnHover'] : _flexslider_optionset_defaults('pauseOnHover'),
358
  );
359
  $form['advanced']['controlsContainer'] = array(
360
    '#type' => 'textfield',
361
    '#title' => t('Controls container (Advanced)'),
362
    '#description' => t('Declare which container the navigation elements should be appended too. Default container is the flexSlider element. Example use would be ".flexslider-container", "#container", etc. If the given element is not found, the default action will be taken.'),
363
    '#default_value' => isset($options['controlsContainer']) ? $options['controlsContainer'] : _flexslider_optionset_defaults('controlsContainer'),
364
  );
365
  $form['advanced']['manualControls'] = array(
366
    '#type' => 'textfield',
367
    '#title' => t('Manual controls (Advanced)'),
368
    '#description' => t('Declare custom control navigation. Example would be ".flex-control-nav li" or "#tabs-nav li img", etc. The number of elements in your controlNav should match the number of slides/tabs.'),
369
    '#default_value' => isset($options['manualControls']) ? $options['manualControls'] : _flexslider_optionset_defaults('manualControls'),
370
  );
371

    
372
  return $form;
373
}
374

    
375
/**
376
 * Form builder; Form to edit a given option set.
377
 */
378
function flexslider_form_optionset_edit($form, &$form_state) {
379

    
380
  if (empty($form_state['optionset'])) {
381
    $optionset = flexslider_optionset_create();
382
  }
383
  else {
384
    $optionset = $form_state['optionset'];
385
  }
386

    
387
  // Title
388
  $form['title'] = array(
389
    '#type' => 'textfield',
390
    '#maxlength' => '255',
391
    '#title' => t('Title'),
392
    '#description' => t('A human-readable title for this option set.'),
393
    '#required' => TRUE,
394
    '#default_value' => $optionset->title,
395
  );
396
  $form['name'] = array(
397
    '#type' => 'machine_name',
398
    '#maxlength' => '255',
399
    '#machine_name' => array(
400
      'source' => array('title'),
401
      'exists' => 'flexslider_optionset_exists',
402
    ),
403
    '#required' => TRUE,
404
    '#default_value' => $optionset->name,
405
  );
406

    
407
  // Show select boxes for the various image styles (thumbnail, normal, big)
408
  $image_style = image_style_options(FALSE);
409
  $form['image_style'] = array(
410
    '#type' => 'fieldset',
411
    '#title' => 'Image style',
412
    '#tree' => TRUE,
413
  );
414
  $form['image_style']['normal'] = array(
415
    '#type' => 'select',
416
    '#title' => t('Normal image style'),
417
    '#description' => t('Image style for the main stage images.'),
418
    '#empty_option' => t('None (original image)'),
419
    '#options' => $image_style,
420
    '#default_value' => $optionset->imagestyle_normal,
421
  );
422
  $form['image_style']['thumbnail'] = array(
423
    '#type' => 'select',
424
    '#title' => t('Thumbnail image style'),
425
    '#description' => t('Image style for the thumbnail images.'),
426
    '#empty_option' => t('None (original image)'),
427
    '#options' => $image_style,
428
    '#default_value' => $optionset->imagestyle_thumbnail,
429
    // @todo enable/disable this option based on the type of options selected
430
    // Ex: Thumbnails should be enabled
431
  );
432

    
433
  // Options Vertical Tab Group table
434
  $form['options'] = array(
435
    '#type' => 'vertical_tabs',
436
  );
437

    
438
  $default_options = flexslider_option_elements($optionset->options);
439
  // Add the options to the vertical tabs section
440
  foreach ($default_options as $key => $value) {
441
    $form['options'][] = $value;
442
  }
443

    
444
  return $form;
445
}
446

    
447
/**
448
 * Validate a form element that should have an integer value.
449
 */
450
function _flexslider_validate_positive_integer($element, &$form_state) {
451
  $value = $element['#value'];
452
  if ($value !== '' && (!is_numeric($value) || intval($value) != $value || $value < 0)) {
453
    form_error($element, t('%name must be a positive integer.', array('%name' => $element['#title'])));
454
  }
455
}
456

    
457
/**
458
 * Validate a form element that should have a number as value.
459
 */
460
function _flexslider_validate_number($element, &$form_state) {
461
  $value = $element['#value'];
462
  if ($value !== '' && !is_numeric($value)) {
463
    form_error($element, t('%name must be a number.', array('%name' => $element['#option_name'])));
464
  }
465
}
466

    
467
/**
468
 * Form builder; Form to delete a given option set.
469
 */
470
function flexslider_optionset_form_delete($form, &$form_state, $optionset) {
471
  $form_state['optionset'] = &$optionset;
472

    
473
  // Deleting an export in code will revert it.
474
  $op = ($optionset->export_type & EXPORT_IN_CODE) ? 'Revert' : 'Delete';
475

    
476
  return confirm_form(
477
    $form,
478
    t('Are you sure you want to @action the option set %name?', array('@action' => t(drupal_strtolower($op)), '%name' => $optionset->name)),
479
    'admin/config/media/flexslider',
480
    NULL,
481
    t($op),  t('Cancel')
482
  );
483
}
484

    
485
/**
486
 * Submit handler for deleting an option set.
487
 */
488
function flexslider_optionset_form_delete_submit($form, &$form_state) {
489
  $optionset = &$form_state['optionset'];
490
  $op = ($optionset->export_type & EXPORT_IN_CODE) ? 'reverted' : 'deleted';
491

    
492
  ctools_include('export');
493
  ctools_export_crud_delete('flexslider_optionset', $optionset);
494

    
495
  drupal_set_message(t('Option set %name was ' . $op . '.', array('%name' => $optionset->name)));
496
  $form_state['redirect'] = 'admin/config/media/flexslider';
497
}
498

    
499

    
500
/**
501
 * Form builder; Form for advanced module settings.
502
 */
503
function flexslider_form_settings() {
504
  $form = array();
505

    
506
  $form['library'] = array(
507
    '#type' => 'fieldset',
508
    '#title' => 'Library',
509
  );
510

    
511
  // Debug mode toggle
512
  $form['library']['flexslider_debug'] = array(
513
    '#type' => 'checkbox',
514
    '#title' => t('Enable debug mode'),
515
    '#description' => t('Load the human-readable version of the FlexSlider library.'),
516
    '#default_value' => variable_get('flexslider_debug', FALSE),
517
    '#access' => user_access('administer flexslider'),
518
  );
519

    
520
  return system_settings_form($form);
521
}
522

    
523
/**
524
 * Submit handler for the advanced module settings.
525
 */
526
function flexslider_form_settings_submit($form, &$form_state) {
527
  // Do nothing for now
528
}
529

    
530
/**
531
 * Validation functions
532
 */
533
function _flexslider_validate_namespace($element, &$form_state) {
534
  // @todo
535
  // @see form_error()
536
  return TRUE;
537
}
538

    
539
function _flexslider_validate_selector($element, &$form_state) {
540
  // @todo
541
  // @see form_error()
542
  return TRUE;
543
}
544

    
545
/**
546
 * Validate a form element that should have a number as value.
547
 */
548
function _flexslider_validate_minimum_version_22($element, &$form_state) {
549
  $lib = libraries_detect('flexslider');
550
  $version = $lib['version'];
551
  $required = "2.2";
552

    
553
  if (!version_compare($version, $required, '>=')) {
554
    form_error($element, t('To use %name you must install FlexSlider version !required or higher.', array(
555
      '%name' => $element['#title'],
556
      '!required' => l($required, 'https://github.com/woothemes/FlexSlider/tree/version/2.2'),
557
    )));
558
  }
559
}