1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Provide diff field functions for the List module.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Diff field callback for parsing list field comparative values.
|
10 |
|
|
*/
|
11 |
|
|
function list_field_diff_view($items, $context) {
|
12 |
|
|
$field = $context['field'];
|
13 |
|
|
$instance = $context['instance'];
|
14 |
|
|
$settings = $context['settings'];
|
15 |
|
|
|
16 |
|
|
$diff_items = array();
|
17 |
|
|
$allowed_values = list_allowed_values($field, $instance, $context['entity_type'], $context['entity']);
|
18 |
|
|
foreach ($items as $delta => $item) {
|
19 |
|
|
// Fairly complex condition to prevent duplicate "key (key)" type rendering.
|
20 |
|
|
if (isset($allowed_values[$item['value']]) &&
|
21 |
|
|
$allowed_values[$item['value']] != $item['value'] &&
|
22 |
|
|
strlen($allowed_values[$item['value']])) {
|
23 |
|
|
switch ($settings['compare']) {
|
24 |
|
|
case 'both':
|
25 |
|
|
$diff_items[$delta] = $allowed_values[$item['value']] . ' (' . $item['value'] . ')';
|
26 |
|
|
break;
|
27 |
|
|
|
28 |
|
|
case 'label':
|
29 |
|
|
$diff_items[$delta] = $allowed_values[$item['value']];
|
30 |
|
|
break;
|
31 |
|
|
|
32 |
|
|
default:
|
33 |
|
|
$diff_items[$delta] = $item['value'];
|
34 |
|
|
break;
|
35 |
|
|
|
36 |
|
|
}
|
37 |
|
|
}
|
38 |
|
|
else {
|
39 |
|
|
// If no match was found for the label, fall back to the key.
|
40 |
|
|
$diff_items[$delta] = $item['value'];
|
41 |
|
|
}
|
42 |
|
|
}
|
43 |
|
|
return $diff_items;
|
44 |
|
|
}
|
45 |
|
|
|
46 |
|
|
/**
|
47 |
|
|
* Provide default field comparison options.
|
48 |
|
|
*/
|
49 |
|
|
function list_field_diff_default_options($field_type) {
|
50 |
|
|
return array(
|
51 |
|
|
'compare' => 'label',
|
52 |
|
|
);
|
53 |
|
|
}
|
54 |
|
|
|
55 |
|
|
/**
|
56 |
|
|
* Provide a form for setting the field comparison options.
|
57 |
|
|
*/
|
58 |
|
|
function list_field_diff_options_form($field_type, $settings) {
|
59 |
|
|
$options_form = array();
|
60 |
|
|
$options_form['compare'] = array(
|
61 |
|
|
'#type' => 'radios',
|
62 |
|
|
'#title' => t('Comparison method'),
|
63 |
|
|
'#options' => array(
|
64 |
|
|
'label' => t('Label'),
|
65 |
|
|
'key' => t('Key'),
|
66 |
|
|
'both' => t('Label (key)'),
|
67 |
|
|
),
|
68 |
|
|
'#default_value' => $settings['compare'],
|
69 |
|
|
);
|
70 |
|
|
return $options_form;
|
71 |
|
|
} |