Projet

Général

Profil

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

root / drupal7 / sites / all / modules / date / date_admin.inc @ 599a39cd

1
<?php
2

    
3
/**
4
 * @file
5
 * Date administration functionality.
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
  $date_formats = date_format_type_options();
18
  $form['format_type'] = array(
19
    '#title' => t('Choose how users view dates and times:'),
20
    '#type' => 'select',
21
    '#options' => $date_formats + array('custom' => t('Custom')),
22
    '#default_value' => $settings['format_type'],
23
    '#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'))),
24
    '#weight' => 0,
25
  );
26

    
27
  $form['custom_date_format'] = array(
28
    '#type' => 'textfield',
29
    '#title' => t('Custom date format'),
30
    '#description' => t('If "Custom", see the <a href="@url" target="_blank">PHP manual</a> for date formats. Otherwise, enter the number of different time units to display, which defaults to 2.', array('@url' => 'http://php.net/manual/function.date.php')),
31
    '#default_value' => isset($settings['custom_date_format']) ? $settings['custom_date_format'] : '',
32
    '#dependency' => array('edit-options-settings-format-type' => array('custom')),
33
  );
34

    
35
  $form['fromto'] = array(
36
    '#title' => t('Display:'),
37
    '#type' => 'select',
38
    '#options' => array(
39
      'both' => t('Both Start and End dates'),
40
      'value' => t('Start date only'),
41
      'value2' => t('End date only'),
42
    ),
43
    '#access' => $field['settings']['todate'],
44
    '#default_value' => $settings['fromto'],
45
    '#weight' => 1,
46
  );
47

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

    
63
  list($prefix, $suffix) = explode('@isodate', t('starting from @isodate'));
64
  $form['multiple_from'] = array(
65
    '#type' => 'textfield',
66
    '#size' => 15,
67
    '#field_prefix' => $prefix,
68
    '#field_suffix' => $suffix,
69
    '#default_value' => $settings['multiple_from'],
70
    '#weight' => 3,
71
    '#access' => ($field['cardinality'] == FIELD_CARDINALITY_UNLIMITED) || ($field['cardinality'] > 1),
72
  );
73

    
74
  list($prefix, $suffix) = explode('@isodate', t('ending with @isodate'));
75
  $form['multiple_to'] = array(
76
    '#type' => 'textfield',
77
    '#size' => 15,
78
    '#field_prefix' => $prefix,
79
    '#field_suffix' => $suffix,
80
    '#default_value' => $settings['multiple_to'],
81
    '#weight' => 4,
82
    '#access' => ($field['cardinality'] == FIELD_CARDINALITY_UNLIMITED) || ($field['cardinality'] > 1),
83
    '#description' => t('Identify specific start and/or end dates in the format YYYY-MM-DDTHH:MM:SS, or leave blank for all available dates.'),
84
  );
85

    
86
  $form['show_remaining_days'] = array(
87
    '#title' => t('Show remaining days'),
88
    '#type' => 'checkbox',
89
    '#default_value' => $settings['show_remaining_days'],
90
    '#weight' => 0,
91
  );
92
  return $form;
93
}
94

    
95
/**
96
 * Settings for the interval formatter.
97
 */
98
function date_interval_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
99
  $display = $instance['display'][$view_mode];
100
  $settings = $display['settings'];
101
  $form = array();
102
  $form['interval'] = array(
103
    '#title' => t('Interval'),
104
    '#description' => t("How many time units should be shown in the 'time ago' string."),
105
    '#type' => 'select',
106
    '#options' => drupal_map_assoc(range(1, 6)),
107
    '#default_value' => $settings['interval'],
108
    '#weight' => 0,
109
  );
110
  // Uses the same options used by Views format_interval.
111
  $options = array(
112
    'raw time ago' => t('Time ago'),
113
    'time ago' => t('Time ago (with "ago" appended)'),
114
    'raw time hence' => t('Time hence'),
115
    'time hence' => t('Time hence (with "hence" appended)'),
116
    'raw time span' => t('Time span (future dates have "-" prepended)'),
117
    'inverse time span' => t('Time span (past dates have "-" prepended)'),
118
    'time span' => t('Time span (with "ago/hence" appended)'),
119
  );
120
  $form['interval_display'] = array(
121
    '#title' => t('Display'),
122
    '#description' => t("How to display the time ago or time hence for this field."),
123
    '#type' => 'select',
124
    '#options' => $options,
125
    '#default_value' => $settings['interval_display'],
126
    '#weight' => 0,
127
  );
128
  if (!empty($field['settings']['todate'])) {
129
    $form['use_end_date'] = array(
130
      '#title' => t('Use End date'),
131
      '#description' => 'Use the End date, instead of the start date',
132
      '#type' => 'checkbox',
133
      '#default_value' => $settings['use_end_date'],
134
    );
135
  }
136
  return $form;
137
}
138

    
139
/**
140
 * Settings summary for the default formatter.
141
 */
142
function date_default_formatter_settings_summary($field, $instance, $view_mode) {
143
  $display = $instance['display'][$view_mode];
144
  $settings = $display['settings'];
145
  $formatter = $display['type'];
146
  $format_types = date_format_type_options();
147
  $summary = array();
148
  $format = FALSE;
149
  switch ($formatter) {
150
    case 'date_plain':
151
      $format = t('Plain');
152
      break;
153

    
154
    case 'format_interval':
155
      $format = t('Interval');
156
      break;
157

    
158
    default:
159
      if (!empty($format_types[$settings['format_type']])) {
160
        $format = $format_types[$settings['format_type']];
161
      }
162
  }
163
  if ($format) {
164
    $summary[] = t('Display dates using the @format format', array('@format' => $format));
165
  }
166
  else {
167
    $summary[] = t('Display dates using the default format because the specified format (@format) is not defined', array('@format' => $settings['format_type']));
168
  }
169

    
170
  if (array_key_exists('fromto', $settings) && $field['settings']['todate']) {
171
    $options = array(
172
      'both' => t('Display both Start and End dates'),
173
      'value' => t('Display Start date only'),
174
      'value2' => t('Display End date only'),
175
    );
176
    if (isset($options[$settings['fromto']])) {
177
      $summary[] = $options[$settings['fromto']];
178
    }
179
  }
180

    
181
  if (array_key_exists('multiple_number', $settings) && !empty($field['cardinality'])) {
182
    $summary[] = t('Show @count value(s) starting with @date1, ending with @date2', array(
183
      '@count' => !empty($settings['multiple_number']) ? $settings['multiple_number'] : t('all'),
184
      '@date1' => !empty($settings['multiple_from']) ? $settings['multiple_from'] : t('earliest'),
185
      '@date2' => !empty($settings['multiple_to']) ? $settings['multiple_to'] : t('latest'),
186
    ));
187
  }
188

    
189
  if (array_key_exists('show_remaining_days', $settings)) {
190
    $summary[] = t('Show remaining days: @value', array('@value' => ($settings['show_remaining_days'] ? 'yes' : 'no')));
191
  }
192

    
193
  return $summary;
194
}
195

    
196
/**
197
 * Settings summary for the interval formatter.
198
 *
199
 * @todo Add settings later.
200
 */
201
function date_interval_formatter_settings_summary($field, $instance, $view_mode) {
202
  $summary = array();
203
  $display = $instance['display'][$view_mode];
204
  $settings = $display['settings'];
205
  $formatter = $display['type'];
206
  $field = ($settings['use_end_date'] == 1) ? 'End' : 'Start';
207
  $summary[] = t('Display time ago, showing @interval units. Using @field Date',
208
    array('@interval' => $settings['interval'], '@field' => $field));
209

    
210
  return $summary;
211
}
212

    
213
/**
214
 * Helper function for date_field_instance_settings_form().
215
 *
216
 * @see date_field_instance_settings_form_validate()
217
 */
218
function _date_field_instance_settings_form($field, $instance) {
219
  $widget = $instance['widget'];
220
  $settings = $instance['settings'];
221
  $widget_settings = $instance['widget']['settings'];
222

    
223
  $form['default_value'] = array(
224
    '#type' => 'select',
225
    '#title' => t('Default date'),
226
    '#default_value' => $settings['default_value'],
227
    '#options' => array(
228
      'blank'     => t('No default value'),
229
      'now'       => t('Now'),
230
      'strtotime' => t('Relative'),
231
    ),
232
    '#weight' => 1,
233
    '#fieldset' => 'default_values',
234
  );
235

    
236
  $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')));
237
  $form['default_value_code'] = array(
238
    '#type' => 'textfield',
239
    '#title' => t('Relative default value'),
240
    '#description' => $description,
241
    '#default_value' => $settings['default_value_code'],
242
    '#states' => array(
243
      'visible' => array(
244
        ':input[name="instance[settings][default_value]"]' => array(
245
          'value' => 'strtotime',
246
        ),
247
      ),
248
    ),
249
    '#weight' => 1.1,
250
    '#fieldset' => 'default_values',
251
  );
252
  $form['default_value2'] = array(
253
    '#type' => !empty($field['settings']['todate']) ? 'select' : 'hidden',
254
    '#title' => t('Default end date'),
255
    '#default_value' => $settings['default_value2'],
256
    '#options' => array(
257
      'same'      => t('Same as Default date'),
258
      'blank'     => t('No default value'),
259
      'now'       => t('Now'),
260
      'strtotime' => t('Relative'),
261
    ),
262
    '#weight' => 2,
263
    '#fieldset' => 'default_values',
264
  );
265
  $form['default_value_code2'] = array(
266
    '#type' => !empty($field['settings']['todate']) ? 'textfield' : 'hidden',
267
    '#title' => t('Relative default value for end date'),
268
    '#description' => $description,
269
    '#default_value' => $settings['default_value_code2'],
270
    '#states' => array(
271
      'visible' => array(
272
        ':input[name="instance[settings][default_value2]"]' => array(
273
          'value' => 'strtotime',
274
        ),
275
      ),
276
    ),
277
    '#weight' => 2.1,
278
    '#fieldset' => 'default_values',
279
  );
280

    
281
  $form['#element_validate'] = array('date_field_instance_settings_form_validate');
282

    
283
  $context = array(
284
    'field' => $field,
285
    'instance' => $instance,
286
  );
287
  drupal_alter('date_field_instance_settings_form', $form, $context);
288

    
289
  return $form;
290
}
291

    
292
/**
293
 * Form validation handler for _date_field_instance_settings_form().
294
 */
295
function _date_field_instance_settings_form_validate(&$form, &$form_state) {
296
  $settings = $form_state['values']['instance']['settings'];
297

    
298
  if ($settings['default_value'] == 'strtotime') {
299
    $is_strtotime = @strtotime($settings['default_value_code']);
300
    if (!$is_strtotime) {
301
      form_set_error('instance][settings][default_value_code', t('The Strtotime default value is invalid.'));
302
    }
303
  }
304
  if (isset($settings['default_value2']) && $settings['default_value2'] == 'strtotime') {
305
    $is_strtotime = @strtotime($settings['default_value_code2']);
306
    if (!$is_strtotime) {
307
      form_set_error('instance][settings][default_value_code2', t('The Strtotime default value for the End Date is invalid.'));
308
    }
309
  }
310
}
311

    
312
/**
313
 * Helper function for date_field_widget_settings_form().
314
 *
315
 * @see date_field_widget_settings_form_validate()
316
 */
317
function _date_field_widget_settings_form($field, $instance) {
318
  $widget = $instance['widget'];
319
  $settings = $widget['settings'];
320

    
321
  $form = array(
322
    '#element_validate' => array('date_field_widget_settings_form_validate'),
323
  );
324

    
325
  $options = array();
326
  if ($widget['type'] == 'date_popup' && module_exists('date_popup')) {
327
    $formats = date_popup_formats();
328
  }
329
  else {
330
    // Example input formats must show all possible date parts, so add seconds.
331
    $formats = str_replace('i', 'i:s', array_keys(system_get_date_formats('short')));
332
    $formats = drupal_map_assoc($formats);
333
  }
334
  $now = date_example_date();
335
  $options['site-wide'] = t('Short date format: @date', array('@date' => date_format_date($now, 'short')));
336
  foreach ($formats as $f) {
337
    $options[$f] = date_format_date($now, 'custom', $f);
338
  }
339
  $form['input_format'] = array(
340
    '#type' => 'select',
341
    '#title' => t('Date entry options'),
342
    '#default_value' => $settings['input_format'],
343
    '#options' => $options,
344
    '#description' => t('Control the order and format of the options users see.'),
345
    '#weight' => 3,
346
    '#fieldset' => 'date_format',
347
  );
348
  // Only a limited set of formats is available for the Date Popup module.
349
  if ($widget['type'] != 'date_popup') {
350
    $form['input_format']['#options']['custom'] = t('Custom format');
351
    $form['input_format_custom'] = array(
352
      '#type' => 'textfield',
353
      '#title' => t('Custom input format'),
354
      '#default_value' => $settings['input_format_custom'],
355
      '#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')),
356
      '#weight' => 5,
357
      '#fieldset' => 'date_format',
358
      '#attributes' => array('class' => array('indent')),
359
      '#states' => array(
360
        'visible' => array(
361
          ':input[name="instance[widget][settings][input_format]"]' => array('value' => 'custom'),
362
        ),
363
      ),
364
    );
365
  }
366
  else {
367
    $form['input_format_custom'] = array(
368
      '#type' => 'hidden',
369
      '#value' => '',
370
    );
371
  }
372

    
373
  if (in_array($widget['type'], array('date_select', 'date_popup'))) {
374
    $form['year_range'] = array(
375
      '#type' => 'date_year_range',
376
      '#default_value' => $settings['year_range'],
377
      '#fieldset' => 'date_format',
378
      '#weight' => 6,
379
    );
380
    $form['increment'] = array(
381
      '#type' => 'select',
382
      '#title' => t('Time increments'),
383
      '#default_value' => $settings['increment'],
384
      '#options' => array(
385
        1 => t('1 minute'),
386
        5 => t('5 minute'),
387
        10 => t('10 minute'),
388
        15 => t('15 minute'),
389
        30 => t('30 minute'),
390
      ),
391
      '#weight' => 7,
392
      '#fieldset' => 'date_format',
393
    );
394
  }
395
  else {
396
    $form['year_range'] = array(
397
      '#type' => 'hidden',
398
      '#value' => $settings['year_range'],
399
    );
400
    $form['increment'] = array(
401
      '#type' => 'hidden',
402
      '#value' => $settings['increment'],
403
    );
404
  }
405

    
406
  $form['label_position'] = array(
407
    '#type' => 'value',
408
    '#value' => $settings['label_position'],
409
  );
410
  $form['text_parts'] = array(
411
    '#type' => 'value',
412
    '#value' => $settings['text_parts'],
413
  );
414
  $form['advanced'] = array(
415
    '#type' => 'fieldset',
416
    '#title' => t('Advanced settings'),
417
    '#collapsible' => TRUE,
418
    '#collapsed' => TRUE,
419
    '#fieldset' => 'date_format',
420
    '#weight' => 9,
421
  );
422
  if (in_array($widget['type'], array('date_select'))) {
423
    $options = array(
424
      'above' => t('Above'),
425
      'within' => t('Within'),
426
      'none' => t('None'),
427
    );
428
    $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.");
429
  }
430
  else {
431
    $options = array(
432
      'above' => t('Above'),
433
      'none' => t('None'),
434
    );
435
    $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.");
436
  }
437
  $form['advanced']['label_position'] = array(
438
    '#type' => 'radios',
439
    '#options' => $options,
440
    '#default_value' => $settings['label_position'],
441
    '#title' => t('Position of date part labels'),
442
    '#description' => $description,
443
  );
444
  $form['advanced']['text_parts'] = array(
445
    '#theme' => $widget['type'] == 'date_select' ? 'date_text_parts' : NULL,
446
  );
447
  $text_parts = (array) $settings['text_parts'];
448
  foreach (date_granularity_names() as $key => $value) {
449
    if ($widget['type'] == 'date_select') {
450
      $form['advanced']['text_parts'][$key] = array(
451
        '#type' => 'radios',
452
        '#default_value' => in_array($key, $text_parts) ? 1 : 0,
453
        '#options' => array(0 => '', 1 => ''),
454
      );
455
    }
456
    else {
457
      $form['advanced']['text_parts'][$key] = array(
458
        '#type' => 'value',
459
        '#value' => (int) in_array($key, (array) $settings['text_parts']),
460
      );
461
    }
462
  }
463

    
464
  $form['advanced']['no_fieldset'] = array(
465
    '#type' => 'checkbox',
466
    '#title' => t('Render as a regular field'),
467
    '#default_value' => !empty($settings['no_fieldset']),
468
    '#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.'),
469
  );
470

    
471
  $context = array(
472
    'field' => $field,
473
    'instance' => $instance,
474
  );
475
  drupal_alter('date_field_widget_settings_form', $form, $context);
476

    
477
  return $form;
478
}
479

    
480
/**
481
 * Form validation handler for _date_field_widget_settings_form().
482
 */
483
function _date_field_widget_settings_form_validate(&$form, &$form_state) {
484
  // The widget settings are in the wrong place in the form because of #tree on
485
  // the top level.
486
  $settings = $form_state['values']['instance']['widget']['settings'];
487
  $settings = array_merge($settings, $settings['advanced']);
488
  unset($settings['advanced']);
489
  form_set_value(array('#parents' => array('instance', 'widget', 'settings')), $settings, $form_state);
490

    
491
  $widget = &$form_state['values']['instance']['widget'];
492
  // Munge the table display for text parts back into an array of text parts.
493
  if (is_array($widget['settings']['text_parts'])) {
494
    form_set_value($form['text_parts'], array_keys(array_filter($widget['settings']['text_parts'])), $form_state);
495
  }
496

    
497
  if ($widget['settings']['input_format'] === 'custom' && empty($widget['settings']['input_format_custom'])) {
498
    form_set_error('instance][widget][settings][input_format_custom', t('Please enter a custom date format, or choose one of the preset formats.'));
499
  }
500
}
501

    
502
/**
503
 * Helper function for date_field_settings_form().
504
 *
505
 * @see date_field_settings_validate()
506
 */
507
function _date_field_settings_form($field, $instance, $has_data) {
508
  $settings = $field['settings'];
509

    
510
  $form = array(
511
    '#element_validate' => array('date_field_settings_validate'),
512
  );
513

    
514
  // Make sure granularity is in the right format and has no empty values.
515
  if (!empty($settings['granularity']) && is_array($settings['granularity'])) {
516
    $granularity = array_filter($settings['granularity']);
517
  }
518
  $tz_handling = $settings['tz_handling'];
519

    
520
  $description = t('Select the date attributes to collect and store.');
521
  if ($has_data) {
522
    $description .= ' ' . t('Changes to date attributes only effects new or updated content.');
523
  }
524
  $options = date_granularity_names();
525
  $checkbox_year = array(
526
    '#type' => 'checkbox',
527
    '#title' => check_plain($options['year']),
528
    '#value' => 'year',
529
    '#return_value' => 'year',
530
    '#disabled' => TRUE,
531
  );
532
  unset($options['year']);
533
  $form['granularity'] = array(
534
    '#type' => 'checkboxes',
535
    '#title' => t('Date attributes to collect'),
536
    '#default_value' => $granularity,
537
    '#options' => $options,
538
    '#attributes' => array(
539
      'class' => array('container-inline'),
540
    ),
541
    '#description' => $description,
542
    'year' => $checkbox_year,
543
  );
544

    
545
  $description = t('End dates are used to collect duration. E.g., allow an event to start on September 15, and end on September 16.');
546
  $form['enddate_get'] = array(
547
    '#type' => 'checkbox',
548
    '#title' => t('Collect an end date'),
549
    '#description' => $description,
550
    '#default_value' => (empty($settings['todate']) ? FALSE : TRUE),
551
    '#disabled' => $has_data,
552
  );
553
  $form['enddate_required'] = array(
554
    '#type' => 'checkbox',
555
    '#title' => t('Required'),
556
    '#default_value' => ((isset($settings['todate']) && $settings['todate'] === 'required') ? TRUE : FALSE),
557
    '#disabled' => $has_data,
558
    '#states' => array(
559
      'invisible' => array(
560
        'input[name="field[settings][enddate_get]"]' => array('checked' => FALSE),
561
      ),
562
    ),
563
  );
564
  $description = t('Select the timezone handling method for this date field.');
565
  $form['tz_handling'] = array(
566
    '#type' => 'select',
567
    '#title' => t('Time zone handling'),
568
    '#default_value' => $tz_handling,
569
    '#options' => date_timezone_handling_options(),
570
    '#description' => $description,
571
    '#attached' => array(
572
      'js' => array(drupal_get_path('module', 'date') . '/date_admin.js'),
573
    ),
574
  );
575
  // Force this value to hidden because we don't want to allow it to be changed
576
  // right now, but allow it to be a variable if needed.
577
  $form['timezone_db'] = array(
578
    '#type' => 'hidden',
579
    '#value' => date_get_timezone_db($tz_handling),
580
  );
581

    
582
  $form['cache_enabled'] = array(
583
    '#type' => 'checkbox',
584
    '#title' => t('Cache dates'),
585
    '#description' => t('Date objects can be created and cached as date fields are loaded, rather than when they are displayed, to improve performance.'),
586
    '#default_value' => !empty($settings['cache_enabled']),
587
    '#weight' => 10,
588
  );
589
  $form['cache_count'] = array(
590
    '#type' => 'textfield',
591
    '#title' => t('Maximum dates per field'),
592
    '#default_value' => (isset($settings['cache_count'])) ? $settings['cache_count'] : 4,
593
    '#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."),
594
    '#size' => 3,
595
    '#weight' => 11,
596
    '#states' => array(
597
      'visible' => array(
598
        'input[name="field[settings][cache_enabled]"]' => array(
599
          'checked' => TRUE,
600
        ),
601
      ),
602
    ),
603
  );
604

    
605
  $context = array(
606
    'field' => $field,
607
    'instance' => $instance,
608
    'has_data' => $has_data,
609
  );
610
  drupal_alter('date_field_settings_form', $form, $context);
611

    
612
  return $form;
613
}
614

    
615
/**
616
 * Form validation handler for _date_field_settings_form().
617
 */
618
function _date_field_settings_validate(&$form, &$form_state) {
619
  $field = &$form_state['values']['field'];
620

    
621
  if ($field['settings']['tz_handling'] == 'none') {
622
    form_set_value($form['timezone_db'], '', $form_state);
623
  }
624
  else {
625
    form_set_value($form['timezone_db'], date_get_timezone_db($field['settings']['tz_handling']), $form_state);
626
  }
627

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

    
632
  // Extract the correct 'todate' value out of the two end date checkboxes.
633
  if ($field['settings']['enddate_get']) {
634
    if ($field['settings']['enddate_required']) {
635
      $field['settings']['todate'] = 'required';
636
    }
637
    else {
638
      $field['settings']['todate'] = 'optional';
639
    }
640
  }
641
  else {
642
    $field['settings']['todate'] = '';
643
  }
644

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

    
648
  if (!empty($field['settings']['cache_enabled'])) {
649
    if (!is_numeric($field['settings']['cache_count'])) {
650
      form_set_error('field[settings][cache_count]', t('The number of cache values must be a number.'));
651
    }
652
    elseif ($field['settings']['cache_count'] < 0) {
653
      form_set_error('field[settings][cache_count]', t('The number of cache values must be a number 0 or greater.'));
654
    }
655
  }
656
}
657

    
658
/**
659
 * Timezone handling options.
660
 *
661
 * The 'none' option will do no timezone conversions and will store and display
662
 * dates exactly as entered useful in locales or situations where timezone
663
 * conversions are not working reliably, for dates with no times, for historical
664
 * dates where timezones are irrelevant, or anytime conversion is unnecessary or
665
 * undesirable.
666
 */
667
function date_timezone_handling_options() {
668
  return array(
669
    'site' => t("Site's time zone"),
670
    'date' => t("Date's time zone"),
671
    'user' => t("User's time zone"),
672
    'utc'  => 'UTC',
673
    'none' => t('No time zone conversion'),
674
  );
675
}