Projet

Général

Profil

Paste
Télécharger (22,9 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / date / date_admin.inc @ b720ea3e

1
<?php
2

    
3
/**
4
 * @file
5
 * Date administration code.
6
 */
7

    
8
/**
9
 * Settings for the default formatter.
10
 */
11
function date_default_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
12
  $display = $instance['display'][$view_mode];
13
  $settings = $display['settings'];
14
  $formatter = $display['type'];
15
  $form = array();
16

    
17
  $form['format_type'] = array(
18
    '#title' => t('Choose how users view dates and times:'),
19
    '#type' => 'select',
20
    '#options' => date_format_type_options(),
21
    '#default_value' => $settings['format_type'],
22
    '#description' => t('To add or edit options, visit <a href="@date-time-page">Date and time settings</a>.', array('@date-time-page' => url('admin/config/regional/date-time'))),
23
    '#weight' => 0,
24
  );
25

    
26
  $form['fromto'] = array(
27
    '#title' => t('Display:'),
28
    '#type' => 'select',
29
    '#options' => array(
30
      'both' => t('Both Start and End dates'),
31
      'value' => t('Start date only'),
32
      'value2' => t('End date only'),
33
    ),
34
    '#access' => $field['settings']['todate'],
35
    '#default_value' => $settings['fromto'],
36
    '#weight' => 1,
37
  );
38

    
39
  // Make the string translatable by keeping it as a whole rather than
40
  // translating prefix and suffix separately.
41
  list($prefix, $suffix) = explode('@count', t('Show @count value(s)'));
42
  $form['multiple_number'] = array(
43
    '#type' => 'textfield',
44
    '#title' => t('Multiple values:'),
45
    '#size' => 5,
46
    '#field_prefix' => $prefix,
47
    '#field_suffix' => $suffix,
48
    '#default_value' => $settings['multiple_number'],
49
    '#weight' => 2,
50
    '#access' => ($field['cardinality'] == FIELD_CARDINALITY_UNLIMITED) || ($field['cardinality'] > 1),
51
    '#description' => t('Identify a specific number of values to display, or leave blank to show all values.'),
52
  );
53

    
54
  list($prefix, $suffix) = explode('@isodate', t('starting from @isodate'));
55
  $form['multiple_from'] = array(
56
    '#type' => 'textfield',
57
    '#size' => 15,
58
    '#field_prefix' => $prefix,
59
    '#field_suffix' => $suffix,
60
    '#default_value' => $settings['multiple_from'],
61
    '#weight' => 3,
62
    '#access' => ($field['cardinality'] == FIELD_CARDINALITY_UNLIMITED) || ($field['cardinality'] > 1),
63
  );
64

    
65
  list($prefix, $suffix) = explode('@isodate', t('ending with @isodate'));
66
  $form['multiple_to'] = array(
67
    '#type' => 'textfield',
68
    '#size' => 15,
69
    '#field_prefix' => $prefix,
70
    '#field_suffix' => $suffix,
71
    '#default_value' => $settings['multiple_to'],
72
    '#weight' => 4,
73
    '#access' => ($field['cardinality'] == FIELD_CARDINALITY_UNLIMITED) || ($field['cardinality'] > 1),
74
    '#description' => t('Identify specific start and/or end dates in the format YYYY-MM-DDTHH:MM:SS, or leave blank for all available dates.'),
75
  );
76

    
77
  $form['show_remaining_days'] = array(
78
    '#title' => t('Show remaining days'),
79
    '#type' => 'checkbox',
80
    '#default_value' => $settings['show_remaining_days'],
81
    '#weight' => 0,
82
  );
83
  return $form;
84
}
85

    
86
/**
87
 * Settings for the interval formatter.
88
 */
89
function date_interval_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
90
  $display = $instance['display'][$view_mode];
91
  $settings = $display['settings'];
92
  $form = array();
93
  $form['interval'] = array(
94
    '#title' => t('Interval'),
95
    '#description' => t("How many time units should be shown in the 'time ago' string."),
96
    '#type' => 'select',
97
    '#options' => drupal_map_assoc(range(1, 6)),
98
    '#default_value' => $settings['interval'],
99
    '#weight' => 0,
100
  );
101
  // Uses the same options used by Views format_interval.
102
  $options = array(
103
    'raw time ago' => t('Time ago'),
104
    'time ago' => t('Time ago (with "ago" appended)'),
105
    'raw time hence' => t('Time hence'),
106
    'time hence' => t('Time hence (with "hence" appended)'),
107
    'raw time span' => t('Time span (future dates have "-" prepended)'),
108
    'inverse time span' => t('Time span (past dates have "-" prepended)'),
109
    'time span' => t('Time span (with "ago/hence" appended)'),
110
  );
111
  $form['interval_display'] = array(
112
    '#title' => t('Display'),
113
    '#description' => t("How to display the time ago or time hence for this field."),
114
    '#type' => 'select',
115
    '#options' => $options,
116
    '#default_value' => $settings['interval_display'],
117
    '#weight' => 0,
118
  );
119
  return $form;
120
}
121

    
122
/**
123
 * Settings summary for the default formatter.
124
 */
125
function date_default_formatter_settings_summary($field, $instance, $view_mode) {
126
  $display = $instance['display'][$view_mode];
127
  $settings = $display['settings'];
128
  $formatter = $display['type'];
129
  $format_types = date_format_type_options();
130
  $summary = array();
131
  $format = FALSE;
132
  switch ($formatter) {
133
    case 'date_plain':
134
      $format = t('Plain');
135
      break;
136

    
137
    case 'format_interval':
138
      $format = t('Interval');
139
      break;
140

    
141
    default:
142
      if (!empty($format_types[$settings['format_type']])) {
143
        $format = $format_types[$settings['format_type']];
144
      }
145
  }
146
  if ($format) {
147
    $summary[] = t('Display dates using the @format format', array('@format' => $format));
148
  }
149
  else {
150
    $summary[] = t('Display dates using the default format because the specified format (@format) is not defined', array('@format' => $settings['format_type']));
151
  }
152

    
153
  if (array_key_exists('fromto', $settings) && $field['settings']['todate']) {
154
    $options = array(
155
      'both' => t('Display both Start and End dates'),
156
      'value' => t('Display Start date only'),
157
      'value2' => t('Display End date only'),
158
    );
159
    if (isset($options[$settings['fromto']])) {
160
      $summary[] = $options[$settings['fromto']];
161
    }
162
  }
163

    
164
  if (array_key_exists('multiple_number', $settings) && !empty($field['cardinality'])) {
165
    $summary[] = t('Show @count value(s) starting with @date1, ending with @date2', array(
166
      '@count' => !empty($settings['multiple_number']) ? $settings['multiple_number'] : t('all'),
167
      '@date1' => !empty($settings['multiple_from']) ? $settings['multiple_from'] : t('earliest'),
168
      '@date2' => !empty($settings['multiple_to']) ? $settings['multiple_to'] : t('latest'),
169
    ));
170
  }
171

    
172
  if (array_key_exists('show_remaining_days', $settings)) {
173
    $summary[] = t('Show remaining days: @value', array('@value' => ($settings['show_remaining_days'] ? 'yes' : 'no')));
174
  }
175

    
176
  return $summary;
177
}
178

    
179
/**
180
 * Settings summary for the interval formatter.
181
 *
182
 * @TODO Add settings later.
183
 */
184
function date_interval_formatter_settings_summary($field, $instance, $view_mode) {
185
  $summary = array();
186
  $display = $instance['display'][$view_mode];
187
  $settings = $display['settings'];
188
  $formatter = $display['type'];
189
  $summary[] = t('Display time ago, showing @interval units.', array('@interval' => $settings['interval']));
190

    
191
  return $summary;
192
}
193

    
194
/**
195
 * Helper function for date_field_instance_settings_form().
196
 *
197
 * @see date_field_instance_settings_form_validate()
198
 */
199
function _date_field_instance_settings_form($field, $instance) {
200
  $widget = $instance['widget'];
201
  $settings = $instance['settings'];
202
  $widget_settings = $instance['widget']['settings'];
203

    
204
  $form['default_value'] = array(
205
    '#type' => 'select',
206
    '#title' => t('Default date'),
207
    '#default_value' => $settings['default_value'],
208
    '#options' => array(
209
      'blank'     => t('No default value'),
210
      'now'       => t('Now'),
211
      'strtotime' => t('Relative'),
212
    ),
213
    '#weight' => 1,
214
    '#fieldset' => 'default_values',
215
  );
216

    
217
  $description = t("Describe a time by reference to the current day, like '+90 days' (90 days from the day the field is created) or '+1 Saturday' (the next Saturday). See !strtotime for more details.", array('!strtotime' => l(t('strtotime'), 'http://www.php.net/manual/en/function.strtotime.php')));
218
  $form['default_value_code'] = array(
219
    '#type' => 'textfield',
220
    '#title' => t('Relative default value'),
221
    '#description' => $description,
222
    '#default_value' => $settings['default_value_code'],
223
    '#states' => array(
224
      'visible' => array(
225
        ':input[name="instance[settings][default_value]"]' => array(
226
          'value' => 'strtotime',
227
        ),
228
      ),
229
    ),
230
    '#weight' => 1.1,
231
    '#fieldset' => 'default_values',
232
  );
233
  $form['default_value2'] = array(
234
    '#type' => !empty($field['settings']['todate']) ? 'select' : 'hidden',
235
    '#title' => t('Default end date'),
236
    '#default_value' => $settings['default_value2'],
237
    '#options' => array(
238
      'same'      => t('Same as Default date'),
239
      'blank'     => t('No default value'),
240
      'now'       => t('Now'),
241
      'strtotime' => t('Relative'),
242
    ),
243
    '#weight' => 2,
244
    '#fieldset' => 'default_values',
245
  );
246
  $form['default_value_code2'] = array(
247
    '#type' => !empty($field['settings']['todate']) ? 'textfield' : 'hidden',
248
    '#title' => t('Relative default value for end date'),
249
    '#description' => $description,
250
    '#default_value' => $settings['default_value_code2'],
251
    '#states' => array(
252
      'visible' => array(
253
        ':input[name="instance[settings][default_value2]"]' => array(
254
          'value' => 'strtotime',
255
        ),
256
      ),
257
    ),
258
    '#weight' => 2.1,
259
    '#fieldset' => 'default_values',
260
  );
261

    
262
  $form['#element_validate'] = array('date_field_instance_settings_form_validate');
263

    
264
  $context = array(
265
    'field' => $field,
266
    'instance' => $instance,
267
  );
268
  drupal_alter('date_field_instance_settings_form', $form, $context);
269

    
270
  return $form;
271
}
272

    
273
/**
274
 * Form validation handler for _date_field_instance_settings_form().
275
 */
276
function date_field_instance_settings_form_validate(&$form, &$form_state) {
277
  $settings = $form_state['values']['instance']['settings'];
278

    
279
  if ($settings['default_value'] == 'strtotime') {
280
    $is_strtotime = @strtotime($settings['default_value_code']);
281
    if (!$is_strtotime) {
282
      form_set_error('instance][settings][default_value_code', t('The Strtotime default value is invalid.'));
283
    }
284
  }
285
  if (isset($settings['default_value2']) && $settings['default_value2'] == 'strtotime') {
286
    $is_strtotime = @strtotime($settings['default_value_code2']);
287
    if (!$is_strtotime) {
288
      form_set_error('instance][settings][default_value_code2', t('The Strtotime default value for the End Date is invalid.'));
289
    }
290
  }
291
}
292

    
293
/**
294
 * Helper function for date_field_widget_settings_form().
295
 *
296
 * @see date_field_widget_settings_form_validate()
297
 */
298
function _date_field_widget_settings_form($field, $instance) {
299
  $widget = $instance['widget'];
300
  $settings = $widget['settings'];
301

    
302
  $form = array(
303
    '#element_validate' => array('date_field_widget_settings_form_validate'),
304
  );
305

    
306
  $options = array();
307
  if ($widget['type'] == 'date_popup' && module_exists('date_popup')) {
308
    $formats = date_popup_formats();
309
  }
310
  else {
311
    // Example input formats must show all possible date parts, so add seconds.
312
    $formats = str_replace('i', 'i:s', array_keys(system_get_date_formats('short')));
313
    $formats = drupal_map_assoc($formats);
314
  }
315
  $now = date_example_date();
316
  $options['site-wide'] = t('Short date format: @date', array('@date' => date_format_date($now, 'short')));
317
  foreach ($formats as $f) {
318
    $options[$f] = date_format_date($now, 'custom', $f);
319
  }
320
  $form['input_format'] = array(
321
    '#type' => 'select',
322
    '#title' => t('Date entry options'),
323
    '#default_value' => $settings['input_format'],
324
    '#options' => $options,
325
    '#description' => t('Control the order and format of the options users see.'),
326
    '#weight' => 3,
327
    '#fieldset' => 'date_format',
328
  );
329
  // Only a limited set of formats is available for the Date Popup module.
330
  if ($widget['type'] != 'date_popup') {
331
    $form['input_format']['#options']['custom'] = t('Custom format');
332
    $form['input_format_custom'] = array(
333
      '#type' => 'textfield',
334
      '#title' => t('Custom input format'),
335
      '#default_value' => $settings['input_format_custom'],
336
      '#description' => t("Override the input format selected above. Define a php date format string like 'm-d-Y H:i' (see <a href=\"@link\">http://php.net/date</a> for more details).", array('@link' => 'http://php.net/date')),
337
      '#weight' => 5,
338
      '#fieldset' => 'date_format',
339
      '#attributes' => array('class' => array('indent')),
340
      '#states' => array(
341
        'visible' => array(
342
          ':input[name="instance[widget][settings][input_format]"]' => array('value' => 'custom'),
343
        ),
344
      ),
345
    );
346
  }
347
  else {
348
    $form['input_format_custom'] = array(
349
      '#type' => 'hidden',
350
      '#value' => '',
351
    );
352
  }
353

    
354
  if (in_array($widget['type'], array('date_select', 'date_popup'))) {
355
    $form['year_range'] = array(
356
      '#type' => 'date_year_range',
357
      '#default_value' => $settings['year_range'],
358
      '#fieldset' => 'date_format',
359
      '#weight' => 6,
360
    );
361
    $form['increment'] = array(
362
      '#type' => 'select', '#title' => t('Time increments'),
363
      '#default_value' => $settings['increment'],
364
      '#options' => array(
365
        1 => t('1 minute'),
366
        5 => t('5 minute'),
367
        10 => t('10 minute'),
368
        15 => t('15 minute'),
369
        30 => t('30 minute')),
370
      '#weight' => 7,
371
      '#fieldset' => 'date_format',
372
    );
373
  }
374
  else {
375
    $form['year_range'] = array(
376
      '#type' => 'hidden',
377
      '#value' => $settings['year_range'],
378
    );
379
    $form['increment'] = array(
380
      '#type' => 'hidden',
381
      '#value' => $settings['increment'],
382
    );
383
  }
384

    
385
  $form['label_position'] = array(
386
    '#type' => 'value',
387
    '#value' => $settings['label_position'],
388
  );
389
  $form['text_parts'] = array(
390
    '#type' => 'value',
391
    '#value' => $settings['text_parts'],
392
  );
393
  $form['advanced'] = array(
394
    '#type' => 'fieldset',
395
    '#title' => t('Advanced settings'),
396
    '#collapsible' => TRUE,
397
    '#collapsed' => TRUE,
398
    '#fieldset' => 'date_format',
399
    '#weight' => 9,
400
  );
401
  if (in_array($widget['type'], array('date_select'))) {
402
    $options = array(
403
      'above' => t('Above'),
404
      'within' => t('Within'),
405
      'none' => t('None'),
406
    );
407
    $description = t("The location of date part labels, like 'Year', 'Month', or 'Day' . 'Above' displays the label as titles above each date part. 'Within' inserts the label as the first option in the select list and in blank textfields. 'None' doesn't visually label any of the date parts. Theme functions like 'date_part_label_year' and 'date_part_label_month' control label text.");
408
  }
409
  else {
410
    $options = array(
411
      'above' => t('Above'),
412
      'none' => t('None'),
413
    );
414
    $description = t("The location of date part labels, like 'Year', 'Month', or 'Day' . 'Above' displays the label as titles above each date part. 'None' doesn't visually label any of the date parts. Theme functions like 'date_part_label_year' and 'date_part_label_month' control label text.");
415
  }
416
  $form['advanced']['label_position'] = array(
417
    '#type' => 'radios',
418
    '#options' => $options,
419
    '#default_value' => $settings['label_position'],
420
    '#title' => t('Position of date part labels'),
421
    '#description' => $description,
422
  );
423
  $form['advanced']['text_parts'] = array(
424
    '#theme' => $widget['type'] == 'date_select' ? 'date_text_parts' : '',
425
  );
426
  $text_parts = (array) $settings['text_parts'];
427
  foreach (date_granularity_names() as $key => $value) {
428
    if ($widget['type'] == 'date_select') {
429
      $form['advanced']['text_parts'][$key] = array(
430
        '#type' => 'radios',
431
        '#default_value' => in_array($key, $text_parts) ? 1 : 0,
432
        '#options' => array(0 => '', 1 => ''),
433
      );
434
    }
435
    else {
436
      $form['advanced']['text_parts'][$key] = array(
437
        '#type' => 'value',
438
        '#value' => (int) in_array($key, (array) $settings['text_parts']),
439
      );
440
    }
441
  }
442

    
443
  $form['advanced']['no_fieldset'] = array(
444
    '#type' => 'checkbox',
445
    '#title' => t('Render as a regular field'),
446
    '#default_value' => !empty($settings['no_fieldset']),
447
    '#description' => t('Whether to render this field as a regular field instead of a fieldset. The date field elements are wrapped in a fieldset by default, and may not display well without it.'),
448
  );
449

    
450
  $context = array(
451
    'field' => $field,
452
    'instance' => $instance,
453
  );
454
  drupal_alter('date_field_widget_settings_form', $form, $context);
455

    
456
  return $form;
457
}
458

    
459
/**
460
 * Form validation handler for _date_field_widget_settings_form().
461
 */
462
function date_field_widget_settings_form_validate(&$form, &$form_state) {
463
  // The widget settings are in the wrong place in the form because of #tree on
464
  // the top level.
465
  $settings = $form_state['values']['instance']['widget']['settings'];
466
  $settings = array_merge($settings, $settings['advanced']);
467
  unset($settings['advanced']);
468
  form_set_value(array('#parents' => array('instance', 'widget', 'settings')), $settings, $form_state);
469

    
470
  $widget = &$form_state['values']['instance']['widget'];
471
  // Munge the table display for text parts back into an array of text parts.
472
  if (is_array($widget['settings']['text_parts'])) {
473
    form_set_value($form['text_parts'], array_keys(array_filter($widget['settings']['text_parts'])), $form_state);
474
  }
475

    
476
  if ($widget['settings']['input_format'] === 'custom' && empty($widget['settings']['input_format_custom'])) {
477
    form_set_error('instance][widget][settings][input_format_custom', t('Please enter a custom date format, or choose one of the preset formats.'));
478
  }
479
}
480

    
481
/**
482
 * Helper function for date_field_settings_form().
483
 *
484
 * @see date_field_settings_validate()
485
 */
486
function _date_field_settings_form($field, $instance, $has_data) {
487
  $settings = $field['settings'];
488

    
489
  $form = array(
490
    '#element_validate' => array('date_field_settings_validate'),
491
  );
492

    
493
  // Make sure granularity is in the right format and has no empty values.
494
  if (!empty($settings['granularity']) && is_array($settings['granularity'])) {
495
    $granularity = array_filter($settings['granularity']);
496
  }
497
  $tz_handling = $settings['tz_handling'];
498

    
499
  $description = t('Select the date attributes to collect and store.');
500
  if ($has_data) {
501
    $description .= ' ' . t('Changes to date attributes only effects new or updated content.');
502
  }
503
  $options = date_granularity_names();
504
  $checkbox_year = array(
505
    '#type' => 'checkbox',
506
    '#title' => check_plain($options['year']),
507
    '#value' => 'year',
508
    '#return_value' => 'year',
509
    '#disabled' => TRUE,
510
  );
511
  unset($options['year']);
512
  $form['granularity'] = array(
513
    '#type' => 'checkboxes',
514
    '#title' => t('Date attributes to collect'),
515
    '#default_value' => $granularity,
516
    '#options' => $options,
517
    '#attributes' => array(
518
      'class' => array('container-inline'),
519
    ),
520
    '#description' => $description,
521
    'year' => $checkbox_year,
522
  );
523

    
524
  $description = t('End dates are used to collect duration. E.g., allow an event to start on September 15, and end on September 16.');
525
  $form['enddate_get'] = array(
526
    '#type' => 'checkbox',
527
    '#title' => t('Collect an end date'),
528
    '#description' => $description,
529
    '#default_value' => (empty($settings['todate']) ? FALSE : TRUE),
530
    '#disabled' => $has_data,
531
  );
532
  $form['enddate_required'] = array(
533
    '#type' => 'checkbox',
534
    '#title' => t('Required'),
535
    '#default_value' => ((isset($settings['todate']) && $settings['todate'] === 'required') ? TRUE : FALSE),
536
    '#disabled' => $has_data,
537
    '#states' => array(
538
      'invisible' => array(
539
        'input[name="field[settings][enddate_get]"]' => array('checked' => FALSE),
540
      ),
541
    ),
542
  );
543
  $description = t('Select the timezone handling method for this date field.');
544
  $form['tz_handling'] = array(
545
    '#type' => 'select',
546
    '#title' => t('Time zone handling'),
547
    '#default_value' => $tz_handling,
548
    '#options' => date_timezone_handling_options(),
549
    '#description' => $description,
550
    '#attached' => array(
551
      'js' => array(drupal_get_path('module', 'date') . '/date_admin.js'),
552
    ),
553
  );
554
  // Force this value to hidden because we don't want to allow it to be changed
555
  // right now, but allow it to be a variable if needed.
556
  $form['timezone_db'] = array(
557
    '#type' => 'hidden',
558
    '#value' => date_get_timezone_db($tz_handling),
559
  );
560

    
561
  $form['cache_enabled'] = array(
562
    '#type' => 'checkbox',
563
    '#title' => t('Cache dates'),
564
    '#description' => t('Date objects can be created and cached as date fields are loaded rather than when they are displayed to improve performance.'),
565
    '#default_value' => !empty($settings['cache_enabled']),
566
    '#weight' => 10,
567
  );
568
  $form['cache_count'] = array(
569
    '#type' => 'textfield',
570
    '#title' => t('Maximum dates per field'),
571
    '#default_value' => (isset($settings['cache_count'])) ? $settings['cache_count'] : 4,
572
    '#description' => t("If set to '0', all date values on every entity will be cached. Note that caching every date on fields that may have a large number of multiple or repeating values may create a significant performance penalty when the cache is cleared. The suggested setting for multiple value and repeating fields is no more than 4 values per field."),
573
    '#size' => 3,
574
    '#weight' => 11,
575
    '#states' => array(
576
      'visible' => array(
577
        'input[name="field[settings][cache_enabled]"]' => array(
578
          'checked' => TRUE,
579
        ),
580
      ),
581
    ),
582
  );
583

    
584
  $context = array(
585
    'field' => $field,
586
    'instance' => $instance,
587
    'has_data' => $has_data,
588
  );
589
  drupal_alter('date_field_settings_form', $form, $context);
590

    
591
  return $form;
592
}
593

    
594
/**
595
 * Form validation handler for _date_field_settings_form().
596
 */
597
function date_field_settings_validate(&$form, &$form_state) {
598
  $field = &$form_state['values']['field'];
599

    
600
  if ($field['settings']['tz_handling'] == 'none') {
601
    form_set_value($form['timezone_db'], '', $form_state);
602
  }
603
  else {
604
    form_set_value($form['timezone_db'], date_get_timezone_db($field['settings']['tz_handling']), $form_state);
605
  }
606

    
607
  if ($field['settings']['tz_handling'] != 'none' && !in_array('hour', array_filter($field['settings']['granularity']))) {
608
    form_set_error('field[settings][tz_handling]', t('Dates without hours granularity must not use any timezone handling.'));
609
  }
610

    
611
  // Extract the correct 'todate' value out of the two end date checkboxes.
612
  if ($field['settings']['enddate_get']) {
613
    if ($field['settings']['enddate_required']) {
614
      $field['settings']['todate'] = 'required';
615
    }
616
    else {
617
      $field['settings']['todate'] = 'optional';
618
    }
619
  }
620
  else {
621
    $field['settings']['todate'] = '';
622
  }
623

    
624
  // Don't save the pseudo values created in the UI.
625
  unset($field['settings']['enddate_get'], $field['settings']['enddate_required']);
626

    
627
  if (!empty($field['settings']['cache_enabled'])) {
628
    if (!is_numeric($field['settings']['cache_count'])) {
629
      form_set_error('field[settings][cache_count]', t('The number of cache values must be a number.'));
630
    }
631
    elseif ($field['settings']['cache_count'] < 0) {
632
      form_set_error('field[settings][cache_count]', t('The number of cache values must be a number 0 or greater.'));
633
    }
634
  }
635
}
636

    
637
/**
638
 * Timezone handling options.
639
 *
640
 * The 'none' option will do no timezone conversions and will store and display
641
 * dates exactly as entered useful in locales or situations where timezone
642
 * conversions are not working reliably, for dates with no times, for historical
643
 * dates where timezones are irrelevant, or anytime conversion is unnecessary or
644
 * undesirable.
645
 */
646
function date_timezone_handling_options() {
647
  return array(
648
    'site' => t("Site's time zone"),
649
    'date' => t("Date's time zone"),
650
    'user' => t("User's time zone"),
651
    'utc'  => 'UTC',
652
    'none' => t('No time zone conversion'),
653
  );
654
}