1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Provide diff field functions for the Date module.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Diff field callback for parsing date fields comparative values.
|
10
|
*/
|
11
|
function date_field_diff_view($items, $context) {
|
12
|
$diff_items = array();
|
13
|
$display = $context['display'];
|
14
|
$display['settings']['format_type'] = $context['settings']['format_type'];
|
15
|
$display['settings']['fromto'] = $context['settings']['fromto'];
|
16
|
foreach ($items as $delta => $item) {
|
17
|
$date = date_formatter_process('date_default', $context['entity_type'], $context['entity'], $context['field'], $context['instance'], $context['language'], $item, $display);
|
18
|
switch ($display['settings']['fromto']) {
|
19
|
case 'both':
|
20
|
if ($date['value']['formatted'] != $date['value2']['formatted']) {
|
21
|
$diff_items[$delta] = t('@from to @to', array(
|
22
|
'@from' => $date['value']['formatted'],
|
23
|
'@to' => $date['value2']['formatted'],
|
24
|
));
|
25
|
}
|
26
|
else {
|
27
|
$diff_items[$delta] = $date['value']['formatted'];
|
28
|
}
|
29
|
break;
|
30
|
|
31
|
case 'value':
|
32
|
case 'value2':
|
33
|
$diff_items[$delta] = $date[$display['settings']['fromto']]['formatted'];
|
34
|
break;
|
35
|
|
36
|
}
|
37
|
}
|
38
|
return $diff_items;
|
39
|
}
|
40
|
|
41
|
/**
|
42
|
* Provide default field comparison options.
|
43
|
*/
|
44
|
function date_field_diff_default_options($field_type) {
|
45
|
return array(
|
46
|
'format_type' => 'long',
|
47
|
'fromto' => 'both',
|
48
|
);
|
49
|
}
|
50
|
|
51
|
/**
|
52
|
* Provide a form for setting the field comparison options.
|
53
|
*/
|
54
|
function date_field_diff_options_form($field_type, $settings) {
|
55
|
$options_form = array();
|
56
|
|
57
|
$form['format_type'] = array(
|
58
|
'#title' => t('Choose how render dates and times'),
|
59
|
'#type' => 'select',
|
60
|
'#options' => date_format_type_options(),
|
61
|
'#default_value' => $settings['format_type'],
|
62
|
'#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'))),
|
63
|
'#weight' => 0,
|
64
|
);
|
65
|
|
66
|
$form['fromto'] = array(
|
67
|
'#title' => t('Display'),
|
68
|
'#type' => 'select',
|
69
|
'#options' => array(
|
70
|
'both' => t('Both Start and End dates'),
|
71
|
'value' => t('Start date only'),
|
72
|
'value2' => t('End date only'),
|
73
|
),
|
74
|
'#default_value' => $settings['fromto'],
|
75
|
'#weight' => 1,
|
76
|
);
|
77
|
|
78
|
return $options_form;
|
79
|
}
|