1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Provide diff field functions for the image module.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Diff field callback for preloading the image file entities.
|
10 |
|
|
*/
|
11 |
|
|
function image_field_diff_view_prepare(&$old_items, &$new_items, $context) {
|
12 |
|
|
$fids = array();
|
13 |
|
|
foreach (array_merge_recursive($old_items, $new_items) as $info) {
|
14 |
|
|
$fids[$info['fid']] = $info['fid'];
|
15 |
|
|
}
|
16 |
|
|
$files = file_load_multiple($fids);
|
17 |
|
|
|
18 |
|
|
foreach ($old_items as $delta => $info) {
|
19 |
|
|
$old_items[$delta]['file'] = isset($files[$info['fid']]) ? $files[$info['fid']] : NULL;
|
20 |
|
|
}
|
21 |
|
|
foreach ($new_items as $delta => $info) {
|
22 |
|
|
$new_items[$delta]['file'] = isset($files[$info['fid']]) ? $files[$info['fid']] : NULL;
|
23 |
|
|
}
|
24 |
|
|
}
|
25 |
|
|
|
26 |
|
|
/**
|
27 |
|
|
* Diff field callback for parsing image field comparative values.
|
28 |
|
|
*/
|
29 |
|
|
function image_field_diff_view($items, $context) {
|
30 |
|
|
$instance = $context['instance'];
|
31 |
|
|
$settings = $context['settings'];
|
32 |
|
|
|
33 |
|
|
$diff_items = array();
|
34 |
|
|
foreach ($items as $delta => $item) {
|
35 |
|
|
if (isset($item['file'])) {
|
36 |
|
|
$output = array();
|
37 |
|
|
|
38 |
|
|
// We populate as much as possible to allow the best flexability in any
|
39 |
|
|
// string overrides.
|
40 |
|
|
$t_args = array();
|
41 |
|
|
foreach ($item as $key => $value) {
|
42 |
|
|
if (is_scalar($value)) {
|
43 |
|
|
$t_args['!' . $key] = $value;
|
44 |
|
|
}
|
45 |
|
|
}
|
46 |
|
|
// Some states do not have the file properties in the item, so put these
|
47 |
|
|
// out of the main file object.
|
48 |
|
|
if (!empty($item['file'])) {
|
49 |
|
|
$file_values = (array) $item['file'];
|
50 |
|
|
foreach ($file_values as $key => $value) {
|
51 |
|
|
if (is_scalar($value) && !isset($t_args['!' . $key])) {
|
52 |
|
|
$t_args['!' . $key] = $value;
|
53 |
|
|
}
|
54 |
|
|
}
|
55 |
|
|
}
|
56 |
|
|
|
57 |
|
|
$output[] = t('Image: !filename', $t_args);
|
58 |
|
|
if ($settings['compare_alt_field'] && !empty($instance['settings']['alt_field'])) {
|
59 |
|
|
if (!empty($item['alt'])) {
|
60 |
|
|
$output[] = t('Alt: !alt', $t_args);
|
61 |
|
|
}
|
62 |
|
|
}
|
63 |
|
|
if ($settings['compare_title_field'] && !empty($instance['settings']['title_field'])) {
|
64 |
|
|
if (!empty($item['title'])) {
|
65 |
|
|
$output[] = t('Title: !title', $t_args);
|
66 |
|
|
}
|
67 |
|
|
}
|
68 |
|
|
if ($settings['show_id']) {
|
69 |
|
|
$output[] = t('File ID: !fid', $t_args);
|
70 |
|
|
}
|
71 |
661d64c9
|
Assos Assos
|
$separator = $settings['property_separator'] == 'nl' ? "\n" : $settings['property_separator'];
|
72 |
|
|
$diff_items[$delta] = implode($separator, $output);
|
73 |
85ad3d82
|
Assos Assos
|
}
|
74 |
|
|
}
|
75 |
|
|
|
76 |
|
|
return $diff_items;
|
77 |
|
|
}
|
78 |
|
|
|
79 |
|
|
/**
|
80 |
|
|
* Provide default field comparison options.
|
81 |
|
|
*/
|
82 |
|
|
function image_field_diff_default_options($field_type) {
|
83 |
|
|
return array(
|
84 |
|
|
'show_id' => 0,
|
85 |
|
|
'compare_alt_field' => 0,
|
86 |
|
|
'compare_title_field' => 0,
|
87 |
661d64c9
|
Assos Assos
|
'property_separator' => '; ',
|
88 |
85ad3d82
|
Assos Assos
|
);
|
89 |
|
|
}
|
90 |
|
|
|
91 |
|
|
/**
|
92 |
|
|
* Provide a form for setting the field comparison options.
|
93 |
|
|
*/
|
94 |
|
|
function image_field_diff_options_form($field_type, $settings) {
|
95 |
|
|
$options_form = array();
|
96 |
|
|
$options_form['show_id'] = array(
|
97 |
|
|
'#type' => 'checkbox',
|
98 |
|
|
'#title' => t('Show image ID'),
|
99 |
|
|
'#default_value' => $settings['show_id'],
|
100 |
|
|
);
|
101 |
|
|
$options_form['compare_alt_field'] = array(
|
102 |
|
|
'#type' => 'checkbox',
|
103 |
|
|
'#title' => t('Compare <em>Alt</em> field'),
|
104 |
|
|
'#default_value' => $settings['compare_alt_field'],
|
105 |
|
|
'#description' => t('This is only used if the "Enable <em>Alt</em> field" is checked in the instance settings.'),
|
106 |
|
|
);
|
107 |
|
|
$options_form['compare_title_field'] = array(
|
108 |
|
|
'#type' => 'checkbox',
|
109 |
|
|
'#title' => t('Compare <em>Title</em> field'),
|
110 |
|
|
'#default_value' => $settings['compare_title_field'],
|
111 |
|
|
'#description' => t('This is only used if the "Enable <em>Title</em> field" is checked in the instance settings.'),
|
112 |
|
|
);
|
113 |
661d64c9
|
Assos Assos
|
$options_form['property_separator'] = array(
|
114 |
|
|
'#type' => 'select',
|
115 |
|
|
'#title' => t('Property separator'),
|
116 |
|
|
'#default_value' => $settings['property_separator'],
|
117 |
|
|
'#description' => t('Provides the ability to show properties inline or across multiple lines.'),
|
118 |
|
|
'#options' => array(
|
119 |
|
|
', ' => t('Comma (,)'),
|
120 |
|
|
'; ' => t('Semicolon (;)'),
|
121 |
|
|
' ' => t('Space'),
|
122 |
|
|
'nl' => t('New line'),
|
123 |
|
|
),
|
124 |
|
|
);
|
125 |
|
|
// Allow users to set their own separator using variable_set().
|
126 |
|
|
if (!isset($options_form['#options'][$settings['property_separator']])) {
|
127 |
|
|
$options_form['#options'][$settings['property_separator']] = $settings['property_separator'];
|
128 |
|
|
}
|
129 |
85ad3d82
|
Assos Assos
|
return $options_form;
|
130 |
|
|
} |