diff --git a/features.admin.inc b/features.admin.inc
index 760bed7..14d7efa 100644
--- a/features.admin.inc
+++ b/features.admin.inc
@@ -1318,6 +1318,12 @@ function features_cleanup_form($form, $form_state, $cache_clear = FALSE) {
* Themed display of what is different.
*/
function features_feature_diff($feature, $component = NULL) {
+
+ // Build form for setting lines of context / preformat spacing, before calling
+ // features_detect_overrides(), because it may redirect and save processing.
+ $form_state = array();
+ $form = drupal_build_form('features_diff_settings_form', $form_state);
+
drupal_add_css(drupal_get_path('module', 'features') . '/features.css');
module_load_include('inc', 'features', 'features.export');
drupal_set_title($feature->info['name']);
@@ -1338,6 +1344,12 @@ function features_feature_diff($feature, $component = NULL) {
foreach ($overrides as $component => $items) {
$rows[] = array(array('data' => $component, 'colspan' => 4, 'header' => TRUE));
$diff = new Diff(explode("\n", $items['default']), explode("\n", $items['normal']));
+
+ // Submitted form values are always in the URL, so we only check $_GET.
+ if (isset($_GET['lines']) && is_numeric($_GET['lines']) && $_GET['lines'] >= 0) {
+ $formatter->leading_context_lines = $_GET['lines'];
+ $formatter->trailing_context_lines = $_GET['lines'];
+ }
$rows = array_merge($rows, $formatter->format($diff));
}
$header = array(
@@ -1345,15 +1357,91 @@ function features_feature_diff($feature, $component = NULL) {
array('data' => t('Overrides'), 'colspan' => 2),
);
$output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('class' => array('diff', 'features-diff'))));
+
+ if (!empty($_GET['space'])) {
+ drupal_add_css('table.diff td div {white-space: pre;}', array('type' => 'inline', 'preprocess' => FALSE));
+ }
}
else {
$output = "
" . t('No changes have been made to this feature.') . "
";
}
- $output = array('page' => array('#markup' => "{$output}
"));
+
+ $output = array(
+ 'page' => array(
+ '#markup' => (!empty($overrides) ? drupal_render($form) : '')
+ . "{$output}
"
+ )
+ );
return $output;
}
/**
+ * Form builder function for 'lines of context' above diff output.
+ */
+function features_diff_settings_form($form, &$form_state) {
+ $form['lines'] = array(
+ '#type' => 'textfield',
+ '#title' => ('Lines of context'),
+ '#size' => 4,
+ );
+ if (isset($_GET['lines']) && is_numeric($_GET['lines']) && $_GET['lines'] >= 0) {
+ $form['lines']['#default_value'] = $_GET['lines'];
+ }
+
+ $form['space'] = array(
+ '#type' => 'checkbox',
+ '#title' => ('Indent lines'),
+ );
+ if (!empty($_GET['space'])) {
+ $form['space']['#default_value'] = 1;
+ }
+
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Reload page'),
+ );
+ return $form;
+}
+
+/**
+ * Validate function for features_diff_settings_form.
+ */
+function features_diff_settings_form_validate($form, &$form_state) {
+ if (isset($form_state['values']['lines'])) {
+ $lines = $form_state['values']['lines'];
+ if (!is_numeric($lines) || $lines < 0) {
+ form_set_error('lines', 'Lines should be a positive number');
+ }
+ }
+}
+
+/**
+ * Submit function for features_diff_settings_form.
+ */
+function features_diff_settings_form_submit($form, &$form_state) {
+
+ // The easiest way of redirecting to the current URL is filling
+ // $_GET['destination'] with the URL string including query. We can get it
+ // from drupal_get_destination() when filling $_GET parameters correctly.
+ if (isset($form_state['values']['lines'])) {
+ $_GET['lines'] = $form_state['values']['lines'];
+ }
+ else {
+ unset($_GET['lines']);
+ }
+ if (!empty($form_state['values']['space'])) {
+ $_GET['space'] = $form_state['values']['space'];
+ }
+ else {
+ unset($_GET['space']);
+ }
+
+ $d = drupal_get_destination();
+ $_GET['destination'] = $d['destination'];
+ drupal_goto();
+}
+
+/**
* Compare the component names. Used to sort alphabetically.
*/
function features_compare_component_name($a, $b) {
diff --git a/features.css b/features.css
index 9ea4123..9b2dc31 100644
--- a/features.css
+++ b/features.css
@@ -69,6 +69,22 @@ div.features-empty {
color:#999;
}
+#features-diff-settings-form .form-type-textfield,
+#features-diff-settings-form .form-type-textfield label,
+#features-diff-settings-form .form-type-textfield .form-text,
+#features-diff-settings-form .form-type-checkbox {
+ float: left;
+}
+
+#features-diff-settings-form .form-type-textfield .form-text {
+ margin: 3px 0 0 5px;
+}
+
+#features-diff-settings-form .form-type-checkbox,
+#features-diff-settings-form .form-submit {
+ margin: 8px 0 0 20px;
+}
+
form div.buttons {
text-align:center;
}