1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Provide diff field functions for the file module.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Diff field callback for preloading file entities.
|
10 |
|
|
*/
|
11 |
|
|
function file_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 file field comparative values.
|
28 |
|
|
*/
|
29 |
|
|
function file_field_diff_view($items, $context) {
|
30 |
|
|
$field = $context['field'];
|
31 |
|
|
$instance = $context['instance'];
|
32 |
|
|
$settings = $context['settings'];
|
33 |
|
|
|
34 |
|
|
$diff_items = array();
|
35 |
|
|
foreach ($items as $delta => $item) {
|
36 |
|
|
if (isset($item['file'])) {
|
37 |
|
|
$output = array();
|
38 |
|
|
|
39 |
|
|
// We populate as much as possible to allow the best flexability in any
|
40 |
|
|
// string overrides.
|
41 |
|
|
$t_args = array();
|
42 |
|
|
foreach ($item as $key => $value) {
|
43 |
|
|
if (is_scalar($value)) {
|
44 |
|
|
$t_args['!' . $key] = $value;
|
45 |
|
|
}
|
46 |
|
|
}
|
47 |
|
|
// Some states do not have the file properties in the item, so put these
|
48 |
|
|
// out of the main file object.
|
49 |
|
|
if (!empty($item['file'])) {
|
50 |
|
|
$file_values = (array) $item['file'];
|
51 |
|
|
foreach ($file_values as $key => $value) {
|
52 |
|
|
if (is_scalar($value) && !isset($t_args['!' . $key])) {
|
53 |
|
|
$t_args['!' . $key] = $value;
|
54 |
|
|
}
|
55 |
|
|
}
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
$output['file'] = t('File: !filename', $t_args);
|
59 |
|
|
if ($settings['compare_description_field'] && !empty($instance['settings']['description_field'])) {
|
60 |
|
|
if (!empty($item['description'])) {
|
61 |
|
|
$output['description'] = t('Description: !description', $t_args);
|
62 |
|
|
}
|
63 |
|
|
}
|
64 |
|
|
if ($settings['show_id']) {
|
65 |
|
|
$output['fid'] = t('File ID: !fid', $t_args);
|
66 |
|
|
}
|
67 |
|
|
if ($settings['compare_display_field'] && !empty($field['settings']['display_field'])) {
|
68 |
|
|
$output['display'] = $item['display'] ? t('Displayed') : t('Hidden');
|
69 |
|
|
}
|
70 |
|
|
$diff_items[$delta] = implode('; ', $output);
|
71 |
|
|
}
|
72 |
|
|
}
|
73 |
|
|
|
74 |
|
|
return $diff_items;
|
75 |
|
|
}
|
76 |
|
|
|
77 |
|
|
/**
|
78 |
|
|
* Provide default field comparison options.
|
79 |
|
|
*/
|
80 |
|
|
function file_field_diff_default_options($field_type) {
|
81 |
|
|
return array(
|
82 |
|
|
'show_id' => 0,
|
83 |
|
|
'compare_display_field' => 0,
|
84 |
|
|
'compare_description_field' => 0,
|
85 |
|
|
);
|
86 |
|
|
}
|
87 |
|
|
|
88 |
|
|
/**
|
89 |
|
|
* Provide a form for setting the field comparison options.
|
90 |
|
|
*/
|
91 |
|
|
function file_field_diff_options_form($field_type, $settings) {
|
92 |
|
|
$options_form = array();
|
93 |
|
|
$options_form['show_id'] = array(
|
94 |
|
|
'#type' => 'checkbox',
|
95 |
|
|
'#title' => t('Show file ID'),
|
96 |
|
|
'#default_value' => $settings['show_id'],
|
97 |
|
|
);
|
98 |
|
|
$options_form['compare_description_field'] = array(
|
99 |
|
|
'#type' => 'checkbox',
|
100 |
|
|
'#title' => t('Compare description field'),
|
101 |
|
|
'#default_value' => $settings['compare_description_field'],
|
102 |
|
|
'#description' => t('This is only used if the "Enable <em>Description</em> field" is checked in the instance settings.'),
|
103 |
|
|
);
|
104 |
|
|
$options_form['compare_display_field'] = array(
|
105 |
|
|
'#type' => 'checkbox',
|
106 |
|
|
'#title' => t('Compare display state field'),
|
107 |
|
|
'#default_value' => $settings['compare_display_field'],
|
108 |
|
|
'#description' => t('This is only used if the "Enable <em>Display</em> field" is checked in the field settings.'),
|
109 |
|
|
);
|
110 |
|
|
return $options_form;
|
111 |
|
|
} |