diff.admin.inc 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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_default_state_node'] = array(
  22. '#type' => 'select',
  23. '#title' => t('Diff default state'),
  24. '#default_value' => variable_get('diff_default_state_node', 'raw'),
  25. '#options' => array(
  26. 'raw' => t('HTML view'),
  27. 'raw_plain' => t('Plain view'),
  28. ),
  29. '#empty_option' => t('- None -'),
  30. '#description' => t('Default display to show when viewing a diff, html tags in diffed result or as plain text.'),
  31. );
  32. $form['diff_radio_behavior'] = array(
  33. '#type' => 'select',
  34. '#title' => t('Diff radio behavior'),
  35. '#default_value' => variable_get('diff_radio_behavior', 'simple'),
  36. '#options' => array(
  37. 'simple' => t('Simple exclusion'),
  38. 'linear' => t('Linear restrictions'),
  39. ),
  40. '#empty_option' => t('- None -'),
  41. '#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.'),
  42. );
  43. $options = drupal_map_assoc(array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
  44. $form['diff_context_lines_leading'] = array(
  45. '#type' => 'select',
  46. '#title' => t('Leading context lines'),
  47. '#description' => t('This governs the number of unchanged leading context "lines" to preserve.'),
  48. '#default_value' => variable_get('diff_context_lines_leading', 2),
  49. '#options' => $options,
  50. );
  51. $form['diff_context_lines_trailing'] = array(
  52. '#type' => 'select',
  53. '#title' => t('Trailing context lines'),
  54. '#description' => t('This governs the number of unchanged trailing context "lines" to preserve.'),
  55. '#default_value' => variable_get('diff_context_lines_trailing', 2),
  56. '#options' => $options,
  57. );
  58. return system_settings_form($form);
  59. }
  60. /**
  61. * Global entity settings.
  62. */
  63. function diff_admin_global_entity_settings($form, $form_state, $entity_type) {
  64. $entity_info = entity_get_info($entity_type);
  65. drupal_set_title(t('Diff settings for %entity_label entities', array('%entity_label' => $entity_info['label'])), PASS_THROUGH);
  66. $form['diff_show_header_' . $entity_type] = array(
  67. '#type' => 'checkbox',
  68. '#title' => t('Show entity label header'),
  69. '#default_value' => variable_get('diff_show_header_' . $entity_type, 1),
  70. );
  71. $form['diff_admin_path_' . $entity_type] = array(
  72. '#type' => 'checkbox',
  73. '#title' => t('Treat diff pages as administrative'),
  74. '#description' => t('Diff pages are treated as administrative pages by default, although it is up to each module to enforce this and to implement this optional setting.'),
  75. '#default_value' => variable_get('diff_admin_path_' . $entity_type, 1),
  76. );
  77. return system_settings_form($form);
  78. }
  79. /**
  80. * Menu callback - provides an overview of Diff support and global settings.
  81. */
  82. function diff_admin_field_overview() {
  83. $build['info'] = array(
  84. '#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>',
  85. );
  86. $header = array(t('Type'), t('Module'), t('Operations'));
  87. $rows = array();
  88. // Skip field types which have no widget types.
  89. $field_types = field_info_field_types();
  90. $widgets = array();
  91. foreach (field_info_widget_types() as $name => $widget_type) {
  92. foreach ($widget_type['field types'] as $widget_field_type) {
  93. if (isset($field_types[$widget_field_type])) {
  94. $widgets[$widget_field_type][$name] = $widget_type['label'];
  95. }
  96. }
  97. }
  98. foreach ($field_types as $field_name => $field_type) {
  99. if (!empty($widgets[$field_name])) {
  100. $row = array();
  101. $row[] = t('@field_label (%field_type)', array(
  102. '@field_label' => $field_type['label'],
  103. '%field_type' => $field_name,
  104. ));
  105. $row[] = $field_type['module'];
  106. $row[] = l(t('Global settings'), 'admin/config/content/diff/fields/' . $field_name);
  107. $rows[] = $row;
  108. }
  109. }
  110. $build['category_table'] = array(
  111. '#theme' => 'table',
  112. '#header' => $header,
  113. '#rows' => $rows,
  114. '#empty' => t('The system has no configurable fields.'),
  115. );
  116. return $build;
  117. }
  118. /**
  119. * Menu form callback for the field settings.
  120. */
  121. function diff_admin_global_field_settings($form, $form_state, $type) {
  122. module_load_include('diff.inc', 'diff');
  123. $field_types = field_info_field_types();
  124. if (!isset($field_types[$type])) {
  125. drupal_set_message(t('Invalid field type.'), 'error');
  126. drupal_goto('admin/config/content/diff/fields');
  127. }
  128. $field_type = $field_types[$type];
  129. // Set the title to give more context to this page.
  130. drupal_set_title(t('Global settings for %label fields', array(
  131. '%label' => $field_type['label'],
  132. )), PASS_THROUGH);
  133. $variable_name = "diff_{$field_type['module']}_field_{$type}_default_options";
  134. $settings = variable_get($variable_name, array());
  135. $settings = _diff_field_default_settings($field_type['module'], $type, $settings);
  136. $func = $field_type['module'] . '_field_diff_options_form';
  137. if (function_exists($func) && ($options_form = $func($type, $settings))) {
  138. $form[$variable_name] = $options_form;
  139. }
  140. $form[$variable_name]['#tree'] = TRUE;
  141. diff_global_settings_form($form[$variable_name], $form_state, $type, $settings);
  142. return system_settings_form($form);
  143. }