features_override.admin.inc 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * @file
  4. * Page callbacks features overrides admin pages.
  5. */
  6. /**
  7. * Renders the differences for a component and element
  8. */
  9. function features_override_render_differences($component = '', $element = '', $module = '') {
  10. module_load_include('inc', 'features_override', 'features_override.export');
  11. module_load_include('inc', 'features', 'features.export');
  12. drupal_add_css(drupal_get_path('module', 'features_override') . '/features_override.css');
  13. if (empty($module)) {
  14. $differences = features_override_get_overrides($component, $element, TRUE, !empty($component));
  15. }
  16. else {
  17. // only grab the differences for the specific module we are interested in
  18. $differences = array();
  19. foreach ($module->info['features'] as $comp_name => $comp) {
  20. if ($difference = array_filter(features_override_module_component_overrides($module->name, $comp_name, FALSE, TRUE))) {
  21. $differences[$comp_name] = isset($differences[$comp_name]) ? array_merge($difference, $differences[$comp_name]) : $difference;
  22. }
  23. }
  24. }
  25. if (!$differences || !count(array_filter($differences))) {
  26. return t('No overrides were found.');
  27. }
  28. if (!empty($element)) {
  29. $differences = array($element => $differences);
  30. }
  31. if (!empty($component)) {
  32. $differences = array($component => $differences);
  33. }
  34. $rows = array();
  35. foreach ($differences as $component_name => $item) {
  36. $code_change = array();
  37. $code_add = array();
  38. $code_delete = array();
  39. foreach ($item as $element_name => $difference) {
  40. $key = (isset($_GET['key'])) ? $_GET['key'] : '';
  41. if (!empty($key)) {
  42. if (!empty($difference['additions'][$key])) {
  43. return '<pre>' . check_plain(implode("\n",
  44. features_override_features_export_render_addition($difference['additions'][$key], $element_name, $component_name))) .
  45. '</pre>';
  46. }
  47. elseif (!empty($difference['deletions'][$key])) {
  48. return '<pre>' . check_plain(implode("\n",
  49. features_override_features_export_render_deletion($difference['deletions'][$key], $element_name, $component_name))) .
  50. '</pre>';
  51. }
  52. else {
  53. return t('Unable to find referenced information.');
  54. }
  55. }
  56. else {
  57. if (!empty($difference['additions'])) {
  58. foreach ($difference['additions'] as $alter) {
  59. if (is_scalar($alter['value'])) {
  60. $code_change[] = array('<pre>' . check_plain(implode("\n", features_override_features_export_render_addition($alter, $element_name, $component_name))). '</pre>');
  61. }
  62. else {
  63. $code_add[] = array('<pre>' . check_plain(implode("\n", features_override_features_export_render_addition($alter, $element_name, $component_name, FALSE))). '</pre>');
  64. }
  65. }
  66. }
  67. if (!empty($difference['deletions'])) {
  68. foreach ($difference['deletions'] as $alter) {
  69. $code_delete[] = array('<pre>' . check_plain(implode("\n", features_override_features_export_render_deletion($alter, $element_name, $component_name))). '</pre>');
  70. }
  71. }
  72. }
  73. }
  74. if (count($code_add) || count($code_delete) || count($code_change)) {
  75. $rows[] = array(array('data' => $component_name, 'header' => TRUE));
  76. }
  77. if (count($code_change)) {
  78. $rows[] = array('CHANGES');
  79. $rows = array_merge($rows, $code_change);
  80. }
  81. if (count($code_add)) {
  82. $rows[] = array('ADDITIONS');
  83. $rows = array_merge($rows, $code_add);
  84. }
  85. if (count($code_delete)) {
  86. $rows[] = array('DELETIONS');
  87. $rows = array_merge($rows, $code_delete);
  88. }
  89. }
  90. return theme('table', array('rows' => $rows, 'attributes' => array('class' => 'features_override_table')));
  91. }
  92. /**
  93. * Page callback to display the differences between what's in code and
  94. * what is in the db.
  95. *
  96. * @param $feature
  97. * A loaded feature object to display differences for.
  98. * @param $component
  99. * Optional: specific component to display differences for. If excluded, all components are used.
  100. *
  101. * @return Themed display of what is different.
  102. */
  103. function features_override_feature_diff($feature, $component = NULL) {
  104. if (module_exists('diff')) {
  105. module_load_include('inc', 'features', 'features.admin');
  106. $output = features_feature_diff($feature, $component);
  107. $output['diff'] = array(
  108. '#prefix' => '<h2>',
  109. '#markup' => 'Code diff',
  110. '#suffix' => '</h2>',
  111. '#weight' => -98,
  112. );
  113. }
  114. $output['overrides'] = array(
  115. '#markup' => features_override_render_differences('', '', $feature),
  116. '#weight' => -99,
  117. );
  118. return $output;
  119. }