浏览代码

Issue #2330059 by osopolar, fgm: Reduce the size of the settings.

Frederic G. MARAND 10 年之前
父节点
当前提交
64d219657c
共有 2 个文件被更改,包括 30 次插入0 次删除
  1. 1 0
      url_replace_filter.install
  2. 29 0
      url_replace_filter.module

+ 1 - 0
url_replace_filter.install

@@ -39,3 +39,4 @@ function url_replace_filter_requirements($phase) {
 
   return array($req);
 }
+

+ 29 - 0
url_replace_filter.module

@@ -72,7 +72,10 @@ function _url_replace_filter_settings($format) {
     '#theme' => 'url_replace_filter_settings_form',
     '#tree' => TRUE,
   );
+  $form['#submit'][] = '_url_replace_filter_settings_form_submit';
+
   $settings = _url_replace_filter_get_settings($format);
+  $index = 0;
   foreach ($settings as $index => $setting) {
     _url_replace_filter_row_form($form, $format, $index, $setting['original'], $setting['replacement']);
     if (!$setting['original']) {
@@ -88,6 +91,32 @@ function _url_replace_filter_settings($format) {
   return $form;
 }
 
+/**
+ * Submit handler for _url_replace_filter_settings() form.
+ *
+ * - Remove useless empty settings to keep variable as small as possible.
+ */
+function _url_replace_filter_settings_form_submit($form, &$form_state) {
+  $format = $form_state['values']['format'];
+  $format_id = 'url_replace_filter_' . $format;
+  if (!isset($form_state['values'][$format_id])) {
+    return;
+  }
+
+  // Remove empty sets.
+  foreach ($form_state['values'][$format_id] as $key => $value) {
+    if (empty($value['original']) && empty($value['replacement'])) {
+      unset($form_state['values'][$format_id][$key]);
+    }
+  }
+
+  if (empty($form_state['values'][$format_id])) {
+    drupal_set_message(t('URL Replace filter configuration is empty : you could <a href="!edit">remove it</a> from this input format.', array(
+      '!edit' => check_url(url('admin/settings/filters/1')),
+    )), 'warning');
+  }
+}
+
 function _url_replace_filter_row_form(&$form, $format, $index, $original, $replacement) {
   $form['url_replace_filter_'. $format][$index]['original'] = array(
     '#type' => 'textfield',