forked from backdrop-contrib/diff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
diff.admin.inc
263 lines (234 loc) · 9.77 KB
/
diff.admin.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
<?php
/**
* @file
* Administration page callbacks and forms.
*/
/**
* General configuration form for controlling the diff behaviour.
*/
function diff_admin_settings($form, $form_state) {
$help_markup = t('The Diff module replaces the normal <em>Revisions</em> node tab.');
$help_markup .= t(' Diff enhances the listing of revisions with an option to view the differences between any two content revisions.');
$help_markup .= t(' Access to this feature is controlled with the <em>View revisions</em> permission.');
$help_markup .= t(' The feature can be enabled/disabled with <em>Compare revisions</em> settings available on the configuration page for each content type.');
$help_markup .= t(' Diff also provides an optional <em>View changes</em> button while editing a node.');
$form['help'] = array(
'#type' => 'help',
'#markup' => $help_markup,
);
$form['diff_theme'] = array(
'#type' => 'select',
'#title' => t('CSS options'),
'#default_value' => config_get('diff.settings','diff_theme'),
'#options' => array(
'default' => t('Classic'),
'boxes' => t('Boxes'),
),
'#empty_option' => t('- None -'),
'#description' => t('Alter the CSS used when displaying diff results.'),
);
$form['diff_radio_behavior'] = array(
'#type' => 'select',
'#title' => t('Diff radio behavior'),
'#default_value' => config_get('diff.settings','diff_radio_behavior'),
'#options' => array(
'simple' => t('Simple exclusion'),
'linear' => t('Linear restrictions'),
),
'#empty_option' => t('- None -'),
'#description' => t('<em>Simple exclusion</em> means that users will not be able to select the same revision, <em>Linear restrictions</em> means that users can only select older or newer revisions of the current selections.'),
);
$options = backdrop_map_assoc(array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
$form['diff_context_lines_leading'] = array(
'#type' => 'select',
'#title' => t('Leading context lines'),
'#description' => t('This governs the number of unchanged leading context "lines" to preserve.'),
'#default_value' => config_get('diff.settings','diff_context_lines_leading'),
'#options' => $options,
);
$form['diff_context_lines_trailing'] = array(
'#type' => 'select',
'#title' => t('Trailing context lines'),
'#description' => t('This governs the number of unchanged trailing context "lines" to preserve.'),
'#default_value' => config_get('diff.settings','diff_context_lines_trailing'),
'#options' => $options,
);
// Add a submit button
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save configuration'),
);
return $form;
}
/**
* Submit handler for module_settings_form().
*/
function diff_admin_settings_submit($form, &$form_state){
$config = config('diff.settings');
$config->set('diff_theme', $form_state['values']['diff_theme']);
$config->set('diff_radio_behavior', $form_state['values']['diff_radio_behavior']);
$config->set('diff_context_lines_leading', $form_state['values']['diff_context_lines_leading']);
$config->set('diff_context_lines_trailing', $form_state['values']['diff_context_lines_trailing']);
$config->save();
backdrop_set_message(t('The configuration options have been saved.'));
}
/**
* Global entity settings.
*/
function diff_admin_global_entity_settings($form, $form_state, $entity_type) {
$entity_info = entity_get_info($entity_type);
backdrop_set_title(t('Diff settings for %entity_label entities', array('%entity_label' => $entity_info['label'])), PASS_THROUGH);
if ($options = module_invoke_all('entity_diff_options', $entity_type)) {
$form['diff_additional_options_' . $entity_type] = array(
'#type' => 'checkboxes',
'#title' => t('Property options'),
'#default_value' => config_get('diff.settings',"diff_additional_options.$entity_type"),
'#options' => $options,
);
}
else {
$form['diff_additional_options_' . $entity_type] = array(
'#type' => 'value',
'#value' => array(),
);
}
$form['diff_show_header_' . $entity_type] = array(
'#type' => 'checkbox',
'#title' => t('Show entity label row header'),
'#default_value' => config_get('diff.settings',"diff_show_header.$entity_type"),
);
if (user_access('administer permissions')) {
$admin_link = l(t('View the administration theme'), 'admin/people/permissions', array('fragment' => 'edit-view-the-administration-theme'));
}
else {
$admin_link = t('View the administration theme');
}
$form['diff_admin_path_' . $entity_type] = array(
'#type' => 'checkbox',
'#title' => t('Use administration theme'),
'#description' => t('This option will enable users with the <em>!link</em> permission to use the admin theme when doing comparisons.', array('!link' => $admin_link)),
'#default_value' => config_get('diff.settings',"diff_admin_path.$entity_type"),
);
$form['diff_default_state_' . $entity_type] = array(
'#type' => 'select',
'#title' => t('Diff default state'),
'#default_value' => config_get('diff.settings',"diff_default_state.$entity_type"),
'#options' => array(
'raw' => t('HTML view'),
'raw_plain' => t('Plain view'),
),
'#empty_option' => t('- None -'),
'#description' => t('Default display to show when viewing a diff, html tags in diffed result or as plain text.'),
);
// Add a submit button
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save configuration'),
);
return $form;
}
/**
* Submit handler for global_entity_settings_form().
*/
function diff_admin_global_entity_settings_submit($form, &$form_state){
$config = config('diff.settings');
$entity_type = $form_state['build_info']['args'][0];
$config->set("diff_additional_options.$entity_type", $form_state['values']['diff_additional_options_' . $entity_type]);
$config->set("diff_show_header.$entity_type", $form_state['values']['diff_show_header_' . $entity_type]);
$config->set("diff_admin_path.$entity_type", $form_state['values']['diff_admin_path_' . $entity_type]);
$config->set("diff_default_state.$entity_type", $form_state['values']['diff_default_state_' . $entity_type]);
$config->save();
backdrop_set_message(t('The configuration options have been saved.'));
}
/**
* Menu callback - provides an overview of Diff support and global settings.
*/
function diff_admin_field_overview() {
$build['info'] = array(
'#markup' => '<p>' . t('This table provides a summary of the field type support found on the system. It is recommended that you use global settings whenever possible to configure field comparison settings.') . '</p>',
);
$header = array(t('Type'), t('Module'), t('Operations'));
$rows = array();
// Skip field types which have no widget types.
$field_types = field_info_field_types();
$widgets = array();
foreach (field_info_widget_types() as $name => $widget_type) {
foreach ($widget_type['field types'] as $widget_field_type) {
if (isset($field_types[$widget_field_type])) {
$widgets[$widget_field_type][$name] = $widget_type['label'];
}
}
}
foreach ($field_types as $field_name => $field_type) {
if (!empty($widgets[$field_name])) {
$row = array();
$row[] = t('@field_label (%field_type)', array(
'@field_label' => $field_type['label'],
'%field_type' => $field_name,
));
$row[] = $field_type['module'];
$row[] = l(t('Global settings'), 'admin/config/content/diff/fields/' . $field_name);
$rows[] = $row;
}
}
$build['category_table'] = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => t('The system has no configurable fields.'),
);
return $build;
}
/**
* Menu form callback for the field settings.
*/
function diff_admin_global_field_settings($form, $form_state, $type) {
module_load_include('diff.inc', 'diff');
$field_types = field_info_field_types();
if (!isset($field_types[$type])) {
backdrop_set_message(t('Invalid field type.'), 'error');
backdrop_goto('admin/config/content/diff/fields');
}
$field_type = $field_types[$type];
// Set the title to give more context to this page.
backdrop_set_title(t('Global settings for %label fields', array(
'%label' => $field_type['label'],
)), PASS_THROUGH);
$variable_name = "diff_{$field_type['module']}_field_{$type}_default_options";
$setting_name = substr($variable_name, 5);
$setting_name = substr($setting_name, 0,- 16);
$settings = config_get('diff.settings', "diff_field_default_options.$setting_name");
$settings = _diff_field_default_settings($field_type['module'], $type, $settings);
$func = $field_type['module'] . '_field_diff_options_form';
if (function_exists($func) && ($options_form = $func($type, $settings))) {
$form[$variable_name] = $options_form;
}
$form[$variable_name]['#tree'] = TRUE;
diff_global_settings_form($form[$variable_name], $form_state, $type, $settings);
// Add a submit button
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save configuration'),
);
return $form;
}
/**
* Submit handler for global_field_settings_form().
*/
function diff_admin_global_field_settings_submit($form, &$form_state){
form_state_values_clean($form_state);
$config = config('diff.settings');
foreach ($form_state['values'] as $key => $value) {
if (is_array($value) && isset($form_state['values']['array_filter'])) {
$value = array_keys(array_filter($value));
}
$setting_name = substr($key, 5);
$setting_name = substr($setting_name, 0,- 16);
$config->set("diff_field_default_options.$setting_name", $value);
}
$config->save();
backdrop_set_message(t('The configuration options have been saved.'));
}