diff.admin.inc 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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(t('Type'), t('Module'), t('Operations'));
  107. $rows = array();
  108. // Skip field types which have no widget types.
  109. $field_types = field_info_field_types();
  110. $widgets = array();
  111. foreach (field_info_widget_types() as $name => $widget_type) {
  112. foreach ($widget_type['field types'] as $widget_field_type) {
  113. if (isset($field_types[$widget_field_type])) {
  114. $widgets[$widget_field_type][$name] = $widget_type['label'];
  115. }
  116. }
  117. }
  118. foreach ($field_types as $field_name => $field_type) {
  119. if (!empty($widgets[$field_name])) {
  120. $row = array();
  121. $row[] = t('@field_label (%field_type)', array(
  122. '@field_label' => $field_type['label'],
  123. '%field_type' => $field_name,
  124. ));
  125. $row[] = $field_type['module'];
  126. $row[] = l(t('Global settings'), 'admin/config/content/diff/fields/' . $field_name);
  127. $rows[] = $row;
  128. }
  129. }
  130. $build['category_table'] = array(
  131. '#theme' => 'table',
  132. '#header' => $header,
  133. '#rows' => $rows,
  134. '#empty' => t('The system has no configurable fields.'),
  135. );
  136. return $build;
  137. }
  138. /**
  139. * Menu form callback for the field settings.
  140. */
  141. function diff_admin_global_field_settings($form, $form_state, $type) {
  142. module_load_include('diff.inc', 'diff');
  143. $field_types = field_info_field_types();
  144. if (!isset($field_types[$type])) {
  145. drupal_set_message(t('Invalid field type.'), 'error');
  146. drupal_goto('admin/config/content/diff/fields');
  147. }
  148. $field_type = $field_types[$type];
  149. // Set the title to give more context to this page.
  150. drupal_set_title(t('Global settings for %label fields', array(
  151. '%label' => $field_type['label'],
  152. )), PASS_THROUGH);
  153. $variable_name = "diff_{$field_type['module']}_field_{$type}_default_options";
  154. $settings = variable_get($variable_name, array());
  155. $settings = _diff_field_default_settings($field_type['module'], $type, $settings);
  156. $func = $field_type['module'] . '_field_diff_options_form';
  157. if (function_exists($func) && ($options_form = $func($type, $settings))) {
  158. $form[$variable_name] = $options_form;
  159. }
  160. $form[$variable_name]['#tree'] = TRUE;
  161. diff_global_settings_form($form[$variable_name], $form_state, $type, $settings);
  162. return system_settings_form($form);
  163. }