1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Provide diff field functions for the Text module.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Diff field callback for parsing text field comparative values.
|
10 |
|
|
*/
|
11 |
|
|
function text_field_diff_view($items, $context) {
|
12 |
|
|
$field = $context['field'];
|
13 |
|
|
$instance = $context['instance'];
|
14 |
|
|
$settings = $context['settings'];
|
15 |
|
|
|
16 |
|
|
$diff_items = array();
|
17 |
|
|
foreach ($items as $delta => $item) {
|
18 |
|
|
$diff_items[$delta] = array();
|
19 |
|
|
|
20 |
|
|
// Compute the format for appending to the label.
|
21 |
|
|
$format_text = '';
|
22 |
|
|
if ($instance['settings']['text_processing'] && $settings['compare_format']) {
|
23 |
|
|
$format_id = empty($item['format']) ? filter_fallback_format() : $item['format'];
|
24 |
|
|
if ($format = filter_format_load($format_id)) {
|
25 |
|
|
$format_text = $format->name;
|
26 |
|
|
}
|
27 |
|
|
else {
|
28 |
|
|
$format_text = t('Missing format !format', array('!format' => $format_id));
|
29 |
|
|
}
|
30 |
|
|
}
|
31 |
|
|
|
32 |
|
|
// Compare the summary fields.
|
33 |
|
|
$summary = $field['type'] == 'text_with_summary' && $settings['compare_summary'];
|
34 |
|
|
if ($summary) {
|
35 |
|
|
// Allow users to optionally clean system specific characters.
|
36 |
|
|
if (empty($item['summary'])) {
|
37 |
|
|
$diff_items[$delta][] = t('Summary field is empty.');
|
38 |
|
|
}
|
39 |
|
|
else {
|
40 |
|
|
if ($format_text) {
|
41 |
|
|
$diff_items[$delta][] = t('Summary (!text_format):', array('!text_format' => $format_text));
|
42 |
|
|
}
|
43 |
|
|
else {
|
44 |
|
|
$diff_items[$delta][] = t('Summary:');
|
45 |
|
|
}
|
46 |
|
|
$diff_items[$delta][] = diff_normalise_text($item['summary']);
|
47 |
|
|
}
|
48 |
|
|
}
|
49 |
|
|
|
50 |
|
|
// Only show label if field has summary displayed.
|
51 |
|
|
if ($summary) {
|
52 |
|
|
if ($format_text) {
|
53 |
|
|
$diff_items[$delta][] = t('Content (!text_format):', array('!text_format' => $format_text));
|
54 |
|
|
}
|
55 |
|
|
else {
|
56 |
|
|
$diff_items[$delta][] = t('Content:');
|
57 |
|
|
}
|
58 |
|
|
}
|
59 |
|
|
|
60 |
|
|
// Allow users to optionally clean system specific characters.
|
61 |
|
|
$diff_items[$delta][] = diff_normalise_text($item['value']);
|
62 |
|
|
|
63 |
|
|
// If no summary, append the format selection to the bottom of the screen.
|
64 |
|
|
// This prevents adding the "Content (format)" label.
|
65 |
|
|
if ($format_text && !$summary) {
|
66 |
|
|
$diff_items[$delta][] = t('Text format: !text_format', array('!text_format' => $format_text));
|
67 |
|
|
}
|
68 |
|
|
|
69 |
|
|
$diff_items[$delta] = $diff_items[$delta];
|
70 |
|
|
}
|
71 |
|
|
return $diff_items;
|
72 |
|
|
}
|
73 |
|
|
|
74 |
|
|
/**
|
75 |
|
|
* Provide default field comparison options.
|
76 |
|
|
*/
|
77 |
|
|
function text_field_diff_default_options($field_type) {
|
78 |
|
|
// Overrides the global 'markdown' setting which does not escape HTML.
|
79 |
|
|
$settings = array(
|
80 |
|
|
'compare_format' => 0,
|
81 |
|
|
'markdown' => 'drupal_html_to_text',
|
82 |
|
|
'line_counter' => '',
|
83 |
|
|
);
|
84 |
|
|
if ($field_type == 'text_with_summary') {
|
85 |
|
|
$settings += array(
|
86 |
|
|
'compare_summary' => 0,
|
87 |
|
|
);
|
88 |
|
|
}
|
89 |
|
|
|
90 |
|
|
return $settings;
|
91 |
|
|
}
|
92 |
|
|
|
93 |
|
|
/**
|
94 |
|
|
* Provide a form for setting the field comparison options.
|
95 |
|
|
*/
|
96 |
|
|
function text_field_diff_options_form($field_type, $settings) {
|
97 |
|
|
$options_form = array();
|
98 |
|
|
$options_form['compare_format'] = array(
|
99 |
|
|
'#type' => 'checkbox',
|
100 |
|
|
'#title' => t('Compare format'),
|
101 |
|
|
'#default_value' => $settings['compare_format'],
|
102 |
|
|
'#description' => t('This is only used if the "Text processing" instance settings are set to <em>Filtered text (user selects text format)</em>.'),
|
103 |
|
|
);
|
104 |
|
|
if ($field_type == 'text_with_summary') {
|
105 |
|
|
$options_form['compare_summary'] = array(
|
106 |
|
|
'#type' => 'checkbox',
|
107 |
|
|
'#title' => t('Compare summary separately'),
|
108 |
|
|
'#default_value' => $settings['compare_summary'],
|
109 |
|
|
'#description' => t('This is only used if the "Summary input" option is checked in the instance settings.'),
|
110 |
|
|
);
|
111 |
|
|
}
|
112 |
|
|
return $options_form;
|
113 |
|
|
} |