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 |
|
|
$diff_items[$delta] = implode('; ', $output);
|
72 |
|
|
}
|
73 |
|
|
}
|
74 |
|
|
|
75 |
|
|
return $diff_items;
|
76 |
|
|
}
|
77 |
|
|
|
78 |
|
|
/**
|
79 |
|
|
* Provide default field comparison options.
|
80 |
|
|
*/
|
81 |
|
|
function image_field_diff_default_options($field_type) {
|
82 |
|
|
return array(
|
83 |
|
|
'show_id' => 0,
|
84 |
|
|
'compare_alt_field' => 0,
|
85 |
|
|
'compare_title_field' => 0,
|
86 |
|
|
);
|
87 |
|
|
}
|
88 |
|
|
|
89 |
|
|
/**
|
90 |
|
|
* Provide a form for setting the field comparison options.
|
91 |
|
|
*/
|
92 |
|
|
function image_field_diff_options_form($field_type, $settings) {
|
93 |
|
|
$options_form = array();
|
94 |
|
|
$options_form['show_id'] = array(
|
95 |
|
|
'#type' => 'checkbox',
|
96 |
|
|
'#title' => t('Show image ID'),
|
97 |
|
|
'#default_value' => $settings['show_id'],
|
98 |
|
|
);
|
99 |
|
|
$options_form['compare_alt_field'] = array(
|
100 |
|
|
'#type' => 'checkbox',
|
101 |
|
|
'#title' => t('Compare <em>Alt</em> field'),
|
102 |
|
|
'#default_value' => $settings['compare_alt_field'],
|
103 |
|
|
'#description' => t('This is only used if the "Enable <em>Alt</em> field" is checked in the instance settings.'),
|
104 |
|
|
);
|
105 |
|
|
$options_form['compare_title_field'] = array(
|
106 |
|
|
'#type' => 'checkbox',
|
107 |
|
|
'#title' => t('Compare <em>Title</em> field'),
|
108 |
|
|
'#default_value' => $settings['compare_title_field'],
|
109 |
|
|
'#description' => t('This is only used if the "Enable <em>Title</em> field" is checked in the instance settings.'),
|
110 |
|
|
);
|
111 |
|
|
return $options_form;
|
112 |
|
|
} |