Ver Fonte

Issue #2330727 by fgm: module now removes its settings on uninstall.

- also flushes filter cache when being disabled or uninstalled.
Frederic G. MARAND há 9 anos atrás
pai
commit
43f8872540
2 ficheiros alterados com 40 adições e 6 exclusões
  1. 33 1
      url_replace_filter.install
  2. 7 5
      url_replace_filter.module

+ 33 - 1
url_replace_filter.install

@@ -32,7 +32,8 @@ function url_replace_filter_requirements($phase) {
   if ($count) {
     $req['value'] = format_plural($count, "Used in 1 format.", "Used in @count formats.");
     $req['severity'] = REQUIREMENT_OK;
-  } else {
+  }
+  else {
     $req['value'] = t('Module is enabled but no format uses its filter. You should disable the module or use the filter in at least one format.');
     $req['severity'] = REQUIREMENT_INFO;
   }
@@ -40,3 +41,34 @@ function url_replace_filter_requirements($phase) {
   return array($req);
 }
 
+/**
+ * Implementation of hook_disable().
+ *
+ * - Flush filter cache to remove content cached with this filter.
+ */
+function url_replace_filter_disabled() {
+  cache_clear_all('*', 'cache_filter', TRUE);
+}
+
+/**
+ * Implementation of hook_uninstall().
+ *
+ * - Remove all configuration variables for the module.
+ * - Remove instances of the filter in all input formats.
+ * - Flush filter cache to remove content cached with this filter.
+ */
+function url_replace_filter_uninstall() {
+  // Delete configuration variables.
+  foreach (array_keys($GLOBALS['conf']) as $name ) {
+    if (strpos($name, 'url_replace_filter_') === 0) {
+      variable_del($name);
+    }
+  }
+
+  // Remove filter from input formats.
+  $formats = _url_replace_filter_get_formats();
+  foreach ($formats as $format) {
+    db_query("DELETE FROM {filters} WHERE module = 'url_replace_filter'");
+  }
+  cache_clear_all('*', 'cache_filter', TRUE);
+}

+ 7 - 5
url_replace_filter.module

@@ -113,7 +113,7 @@ function _url_replace_filter_settings_form_submit($form, &$form_state) {
   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');
+      )), 'warning');
   }
 }
 
@@ -131,7 +131,9 @@ function _url_replace_filter_row_form(&$form, $format, $index, $original, $repla
 }
 
 function _url_replace_filter_get_settings($format) {
-  return variable_get('url_replace_filter_'. $format, array(0 => array('original' => '', 'replacement' => '')));
+  return variable_get('url_replace_filter_'. $format, array(
+    0 => array('original' => '', 'replacement' => ''),
+  ));
 }
 
 /**
@@ -198,7 +200,7 @@ function url_replace_filter_form_system_modules_alter(array &$form) {
 
   // Description might have been altered, so do not rely on its default value.
   $description = isset($form['description'][$machine_name]['#value'])
-     ? $form['description'][$machine_name]['#value']
+    ? $form['description'][$machine_name]['#value']
     : $human_name;
 
   $format_ids = _url_replace_filter_get_formats();
@@ -216,8 +218,8 @@ function url_replace_filter_form_system_modules_alter(array &$form) {
     $links_array[$format_id] = t($text, array('!link' => $link));
   }
   $links = implode(', ', $links_array);
-  $form['description'][$machine_name]['#value'] = $description
-    . t(' (Configure in !urls)', array('!urls' => $links));
+  $form['description'][$machine_name]['#value'] = $description  .' '.
+    t('(Configure in !urls)', array('!urls' => $links));
 }
 
 /**