diff.admin.inc 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. /**
  3. * @file
  4. * Administration page callbacks and forms.
  5. */
  6. /**
  7. * General configuration form for controlling the diff behaviour.
  8. */
  9. function diff_admin_settings($form, $form_state) {
  10. $form['diff_theme'] = array(
  11. '#type' => 'select',
  12. '#title' => t('CSS options'),
  13. '#default_value' => variable_get('diff_theme', 'default'),
  14. '#options' => array(
  15. 'default' => t('Classic'),
  16. 'boxes' => t('Boxes'),
  17. ),
  18. '#empty_option' => t('- None -'),
  19. '#description' => t('Alter the CSS used when displaying diff results.'),
  20. );
  21. $form['diff_radio_behavior'] = array(
  22. '#type' => 'select',
  23. '#title' => t('Diff radio behavior'),
  24. '#default_value' => variable_get('diff_radio_behavior', 'simple'),
  25. '#options' => array(
  26. 'simple' => t('Simple exclusion'),
  27. 'linear' => t('Linear restrictions'),
  28. ),
  29. '#empty_option' => t('- None -'),
  30. '#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.'),
  31. );
  32. $options = drupal_map_assoc(array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
  33. $form['diff_context_lines_leading'] = array(
  34. '#type' => 'select',
  35. '#title' => t('Leading context lines'),
  36. '#description' => t('This governs the number of unchanged leading context "lines" to preserve.'),
  37. '#default_value' => variable_get('diff_context_lines_leading', 2),
  38. '#options' => $options,
  39. );
  40. $form['diff_context_lines_trailing'] = array(
  41. '#type' => 'select',
  42. '#title' => t('Trailing context lines'),
  43. '#description' => t('This governs the number of unchanged trailing context "lines" to preserve.'),
  44. '#default_value' => variable_get('diff_context_lines_trailing', 2),
  45. '#options' => $options,
  46. );
  47. return system_settings_form($form);
  48. }
  49. /**
  50. * Global entity settings.
  51. */
  52. function diff_admin_global_entity_settings($form, $form_state, $entity_type) {
  53. $entity_info = entity_get_info($entity_type);
  54. drupal_set_title(t('Diff settings for %entity_label entities', array('%entity_label' => $entity_info['label'])), PASS_THROUGH);
  55. if ($options = module_invoke_all('entity_diff_options', $entity_type)) {
  56. $form['diff_additional_options_' . $entity_type] = array(
  57. '#type' => 'checkboxes',
  58. '#title' => t('Property options'),
  59. '#default_value' => variable_get('diff_additional_options_' . $entity_type, array()),
  60. '#options' => $options,
  61. );
  62. }
  63. else {
  64. $form['diff_additional_options_' . $entity_type] = array(
  65. '#type' => 'value',
  66. '#value' => array(),
  67. );
  68. }
  69. $form['diff_show_header_' . $entity_type] = array(
  70. '#type' => 'checkbox',
  71. '#title' => t('Show entity label row header'),
  72. '#default_value' => variable_get('diff_show_header_' . $entity_type, 1),
  73. );
  74. if (user_access('administer permissions')) {
  75. $admin_link = l(t('View the administration theme'), 'admin/people/permissions', array('fragment' => 'edit-view-the-administration-theme'));
  76. }
  77. else {
  78. $admin_link = t('View the administration theme');
  79. }
  80. $form['diff_admin_path_' . $entity_type] = array(
  81. '#type' => 'checkbox',
  82. '#title' => t('Use administration theme'),
  83. '#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)),
  84. '#default_value' => variable_get('diff_admin_path_' . $entity_type, 1),
  85. );
  86. $form['diff_default_state_' . $entity_type] = array(
  87. '#type' => 'select',
  88. '#title' => t('Diff default state'),
  89. '#default_value' => variable_get('diff_default_state_' . $entity_type, 'raw'),
  90. '#options' => array(
  91. 'raw' => t('HTML view'),
  92. 'raw_plain' => t('Plain view'),
  93. ),
  94. '#empty_option' => t('- None -'),
  95. '#description' => t('Default display to show when viewing a diff, html tags in diffed result or as plain text.'),
  96. );
  97. return system_settings_form($form);
  98. }
  99. /**
  100. * Menu callback - provides an overview of Diff support and global settings.
  101. */
  102. function diff_admin_field_overview() {
  103. $build['info'] = array(
  104. '#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>',
  105. );
  106. $header = array(
  107. t('Type'),
  108. t('Machine name'),
  109. t('Module'),
  110. t('Operations'),
  111. );
  112. $rows = array();
  113. // Skip field types which have no widget types.
  114. $field_types = field_info_field_types();
  115. $widgets = array();
  116. foreach (field_info_widget_types() as $name => $widget_type) {
  117. foreach ($widget_type['field types'] as $widget_field_type) {
  118. if (isset($field_types[$widget_field_type])) {
  119. $widgets[$widget_field_type][$name] = $widget_type['label'];
  120. }
  121. }
  122. }
  123. foreach ($field_types as $field_name => $field_type) {
  124. if (!empty($widgets[$field_name])) {
  125. $row = array();
  126. $row[] = $field_type['label'];
  127. $row[] = $field_name;
  128. $row[] = $field_type['module'];
  129. $row[] = l(t('Global settings'), 'admin/config/content/diff/fields/' . $field_name);
  130. $rows[] = $row;
  131. }
  132. }
  133. $build['category_table'] = array(
  134. '#theme' => 'table',
  135. '#header' => $header,
  136. '#rows' => $rows,
  137. '#empty' => t('The system has no configurable fields.'),
  138. );
  139. return $build;
  140. }
  141. /**
  142. * Menu form callback for the field settings.
  143. */
  144. function diff_admin_global_field_settings($form, $form_state, $type) {
  145. module_load_include('diff.inc', 'diff');
  146. $field_types = field_info_field_types();
  147. if (!isset($field_types[$type])) {
  148. drupal_set_message(t('Invalid field type.'), 'error');
  149. drupal_goto('admin/config/content/diff/fields');
  150. }
  151. $field_type = $field_types[$type];
  152. // Set the title to give more context to this page.
  153. drupal_set_title(t('Global settings for %label fields', array(
  154. '%label' => $field_type['label'],
  155. )), PASS_THROUGH);
  156. $variable_name = "diff_{$field_type['module']}_field_{$type}_default_options";
  157. $settings = variable_get($variable_name, array());
  158. $settings = _diff_field_default_settings($field_type['module'], $type, $settings);
  159. $func = $field_type['module'] . '_field_diff_options_form';
  160. if (function_exists($func) && ($options_form = $func($type, $settings))) {
  161. $form[$variable_name] = $options_form;
  162. }
  163. $form[$variable_name]['#tree'] = TRUE;
  164. diff_global_settings_form($form[$variable_name], $form_state, $type, $settings);
  165. return system_settings_form($form);
  166. }