Projet

Général

Profil

Paste
Télécharger (6,49 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / diff / diff.admin.inc @ 661d64c9

1
<?php
2

    
3
/**
4
 * @file
5
 * Administration page callbacks and forms.
6
 */
7

    
8
/**
9
 * General configuration form for controlling the diff behaviour.
10
 */
11
function diff_admin_settings($form, $form_state) {
12
  $form['diff_theme'] = array(
13
    '#type' => 'select',
14
    '#title' => t('CSS options'),
15
    '#default_value' => variable_get('diff_theme', 'default'),
16
    '#options' => array(
17
      'default' => t('Classic'),
18
      'boxes' => t('Boxes'),
19
    ),
20
    '#empty_option' => t('- None -'),
21
    '#description' => t('Alter the CSS used when displaying diff results.'),
22
  );
23
  $form['diff_radio_behavior'] = array(
24
    '#type' => 'select',
25
    '#title' => t('Diff radio behavior'),
26
    '#default_value' => variable_get('diff_radio_behavior', 'simple'),
27
    '#options' => array(
28
      'simple' => t('Simple exclusion'),
29
      'linear' => t('Linear restrictions'),
30
    ),
31
    '#empty_option' => t('- None -'),
32
    '#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.'),
33
  );
34

    
35
  $options = drupal_map_assoc(array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
36
  $form['diff_context_lines_leading'] = array(
37
    '#type' => 'select',
38
    '#title' => t('Leading context lines'),
39
    '#description' => t('This governs the number of unchanged leading context "lines" to preserve.'),
40
    '#default_value' => variable_get('diff_context_lines_leading', 2),
41
    '#options' => $options,
42
  );
43
  $form['diff_context_lines_trailing'] = array(
44
    '#type' => 'select',
45
    '#title' => t('Trailing context lines'),
46
    '#description' => t('This governs the number of unchanged trailing context "lines" to preserve.'),
47
    '#default_value' => variable_get('diff_context_lines_trailing', 2),
48
    '#options' => $options,
49
  );
50

    
51
  return system_settings_form($form);
52
}
53

    
54
/**
55
 * Global entity settings.
56
 */
57
function diff_admin_global_entity_settings($form, $form_state, $entity_type) {
58
  $entity_info = entity_get_info($entity_type);
59
  drupal_set_title(t('Diff settings for %entity_label entities', array('%entity_label' => $entity_info['label'])), PASS_THROUGH);
60

    
61
  if ($options = module_invoke_all('entity_diff_options', $entity_type)) {
62
    $form['diff_additional_options_' . $entity_type] = array(
63
      '#type' => 'checkboxes',
64
      '#title' => t('Property options'),
65
      '#default_value' => variable_get('diff_additional_options_' . $entity_type, array()),
66
      '#options' => $options,
67
    );
68
  }
69
  else {
70
    $form['diff_additional_options_' . $entity_type] = array(
71
      '#type' => 'value',
72
      '#value' => array(),
73
    );
74
  }
75

    
76
  $form['diff_show_header_' . $entity_type] = array(
77
    '#type' => 'checkbox',
78
    '#title' => t('Show entity label row header'),
79
    '#default_value' => variable_get('diff_show_header_' . $entity_type, 1),
80
  );
81
  if (user_access('administer permissions')) {
82
    $admin_link = l(t('View the administration theme'), 'admin/people/permissions', array('fragment' => 'edit-view-the-administration-theme'));
83
  }
84
  else {
85
    $admin_link = t('View the administration theme');
86
  }
87
  $form['diff_admin_path_' . $entity_type] = array(
88
    '#type' => 'checkbox',
89
    '#title' => t('Use administration theme'),
90
    '#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)),
91
    '#default_value' => variable_get('diff_admin_path_' . $entity_type, 1),
92
  );
93
  $form['diff_default_state_' . $entity_type] = array(
94
    '#type' => 'select',
95
    '#title' => t('Diff default state'),
96
    '#default_value' => variable_get('diff_default_state_' . $entity_type, 'raw'),
97
    '#options' => array(
98
      'raw' => t('HTML view'),
99
      'raw_plain' => t('Plain view'),
100
    ),
101
    '#empty_option' => t('- None -'),
102
    '#description' => t('Default display to show when viewing a diff, html tags in diffed result or as plain text.'),
103
  );
104
  return system_settings_form($form);
105
}
106

    
107
/**
108
 * Menu callback - provides an overview of Diff support and global settings.
109
 */
110
function diff_admin_field_overview() {
111
  $build['info'] = array(
112
    '#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>',
113
  );
114

    
115
  $header = array(t('Type'), t('Module'), t('Operations'));
116
  $rows = array();
117

    
118
  // Skip field types which have no widget types.
119
  $field_types = field_info_field_types();
120
  $widgets = array();
121
  foreach (field_info_widget_types() as $name => $widget_type) {
122
    foreach ($widget_type['field types'] as $widget_field_type) {
123
      if (isset($field_types[$widget_field_type])) {
124
        $widgets[$widget_field_type][$name] = $widget_type['label'];
125
      }
126
    }
127
  }
128

    
129
  foreach ($field_types as $field_name => $field_type) {
130
    if (!empty($widgets[$field_name])) {
131
      $row = array();
132
      $row[] = t('@field_label (%field_type)', array(
133
        '@field_label' => $field_type['label'],
134
        '%field_type' => $field_name,
135
      ));
136
      $row[] = $field_type['module'];
137
      $row[] = l(t('Global settings'), 'admin/config/content/diff/fields/' . $field_name);
138
      $rows[] = $row;
139
    }
140
  }
141

    
142
  $build['category_table'] = array(
143
    '#theme' => 'table',
144
    '#header' => $header,
145
    '#rows' => $rows,
146
    '#empty' => t('The system has no configurable fields.'),
147
  );
148
  return $build;
149
}
150

    
151
/**
152
 * Menu form callback for the field settings.
153
 */
154
function diff_admin_global_field_settings($form, $form_state, $type) {
155
  module_load_include('diff.inc', 'diff');
156

    
157
  $field_types = field_info_field_types();
158
  if (!isset($field_types[$type])) {
159
    drupal_set_message(t('Invalid field type.'), 'error');
160
    drupal_goto('admin/config/content/diff/fields');
161
  }
162
  $field_type = $field_types[$type];
163

    
164
  // Set the title to give more context to this page.
165
  drupal_set_title(t('Global settings for %label fields', array(
166
    '%label' => $field_type['label'],
167
  )), PASS_THROUGH);
168

    
169
  $variable_name = "diff_{$field_type['module']}_field_{$type}_default_options";
170
  $settings = variable_get($variable_name, array());
171
  $settings = _diff_field_default_settings($field_type['module'], $type, $settings);
172
  $func = $field_type['module'] . '_field_diff_options_form';
173
  if (function_exists($func) && ($options_form = $func($type, $settings))) {
174
    $form[$variable_name] = $options_form;
175
  }
176
  $form[$variable_name]['#tree'] = TRUE;
177

    
178
  diff_global_settings_form($form[$variable_name], $form_state, $type, $settings);
179
  return system_settings_form($form);
180
}