? DELETE
? MISC-FIELD-CHANGES-REAPPLY.patch
? Makefile
? article.macro
? d6-50-nodes.sql.gz
? d7-50-nodes-new.sql.gz
? d7-50-nodes.sql.gz
? head.kpf
? patches
? test.php
? modules/field/field.bulk.update.inc
? modules/syslog/syslog.install
? scripts/OLD-generate-autoload.pl
? scripts/generate-autoload.pl
? sites/all/cck
? sites/all/modules/admin_menu
? sites/all/modules/color
? sites/all/modules/combofield
? sites/all/modules/devel
? sites/all/modules/macro
? sites/all/modules/pbs
? sites/all/modules/pipedream
? sites/all/modules/taint
? sites/default/files
? sites/default/private
? sites/default/settings.php
Index: modules/field/modules/text/text.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/modules/text/text.module,v
retrieving revision 1.61
diff -u -F '^[fc]' -r1.61 text.module
--- modules/field/modules/text/text.module	17 Aug 2010 18:25:31 -0000	1.61
+++ modules/field/modules/text/text.module	17 Aug 2010 20:06:56 -0000
@@ -649,3 +649,14 @@ function text_field_prepare_translation(
     }
   }
 }
+
+/**
+ * Implements hook_filter_format_delete().
+ *
+ * When a text format is deleted, invalidate the field data cache. We
+ * could try to be more clever and only invalid selected cache
+ * elements, but input formats are not deleted that often.
+ */
+function text_filter_format_delete($format, $fallback) {
+  field_cache_clear();
+}
Index: modules/filter/filter.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/filter/filter.module,v
retrieving revision 1.338
diff -u -F '^[fc]' -r1.338 filter.module
--- modules/filter/filter.module	17 Aug 2010 13:50:52 -0000	1.338
+++ modules/filter/filter.module	17 Aug 2010 20:06:57 -0000
@@ -148,6 +148,38 @@ function _filter_delete_format_access($f
   return user_access('administer filters') && ($format->format != filter_fallback_format());
 }
 
+ /**
+ * Set the fallback format for a deleted format.
+ *
+ * @param $format_id
+ *   A format that is deleted.
+ * @param $fallback_id
+ *   The replacement format for $format_id.
+ */
+function _filter_set_replacement_format($format_id, $fallback_id) {
+  $deleted = variable_get('filter_deleted_formats', array());
+  $deleted[$format_id] = $fallback_id;
+  variable_set('filter_deleted_formats', $deleted);
+}
+
+/**
+ * Get a format's replacement format if it has been deleted.
+ *
+ * @param $format_id
+ *   A format that is deleted.
+ * @return
+ *   The replacement format for $format_id if $format_id has been
+ *   deleted, or $format_id if it has not been deleted.
+ */
+function _filter_get_replacement_format($format_id) {
+  $deleted = variable_get('filter_deleted_formats', array());
+  // Handle a chain of deleted formats.
+  while (isset($deleted[$format_id])) {
+    $format_id = $deleted[$format_id];
+  }
+  return $format_id;
+}
+
 /**
  * Load a text format object from the database.
  *
@@ -155,9 +187,15 @@ function _filter_delete_format_access($f
  *   The format ID.
  *
  * @return
- *   A fully-populated text format object.
+ *   A fully-populated text format object. If $format_id refers to a
+ *   previously deleted format (e.g. because existing text field data
+ *   still refers to it), return its replacement format instead. This
+ *   means the returned format may not be $format_id.
  */
 function filter_format_load($format_id) {
+  // If we're being asked to load a format that was previously
+  // deleted, load its replacement format instead.
+  $format_id = _filter_get_replacement_format($format_id);
   $formats = filter_formats();
   return isset($formats[$format_id]) ? $formats[$format_id] : FALSE;
 }
@@ -273,11 +311,16 @@ function filter_format_delete($format, $
     ->condition('format', $format->format)
     ->execute();
 
-  // Allow modules to react on text format deletion.
+  // Determine the replacement format.
   if (empty($fallback_id)) {
     $fallback_id = filter_fallback_format();
   }
   $fallback = filter_format_load($fallback_id);
+
+  // Update the deleted-formats fallback list.
+  _filter_set_replacement_format($format->format, $fallback->format);
+
+  // Allow modules to react on text format deletion.
   module_invoke_all('filter_format_delete', $format, $fallback);
 
   filter_formats_reset();
@@ -819,6 +862,8 @@ function filter_process_format($element)
   if (empty($element['#format'])) {
     $element['#format'] = filter_default_format($user);
   }
+  // If the format has been deleted, use its replacement format.
+  $element['#format'] = _filter_get_replacement_format($element['#format']);
   $element['format']['format'] = array(
     '#type' => 'select',
     '#title' => t('Text format'),
Index: modules/filter/filter.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/filter/filter.test,v
retrieving revision 1.71
diff -u -F '^[fc]' -r1.71 filter.test
--- modules/filter/filter.test	5 Aug 2010 23:53:38 -0000	1.71
+++ modules/filter/filter.test	17 Aug 2010 20:06:57 -0000
@@ -68,6 +68,44 @@ class FilterCRUDTestCase extends DrupalW
   }
 
   /**
+   * Test that when a text format is deleted, calls to check_markup()
+   * using a deleted format use the correct fallback format.
+   */
+  function testTextFormatDeleteFallback() {
+    $filtered_html_format = db_query_range('SELECT * FROM {filter_format} WHERE name = :name', 0, 1, array(':name' => 'Filtered HTML'))->fetchObject();
+    $full_html_format = db_query_range('SELECT * FROM {filter_format} WHERE name = :name', 0, 1, array(':name' => 'Full HTML'))->fetchObject();
+    
+    // Create a node using Full HTML
+    $html_text = '<div>looks different under Full HTML, Filtered HTML, and default fallback format</div>';
+    $node->type = 'article';
+    $node->title = 'fallback test';
+    $node->uid = 1;
+    $node->body[LANGUAGE_NONE][0]['value'] = $html_text;
+    $node->body[LANGUAGE_NONE][0]['format'] = $full_html_format->format;
+    node_save($node);
+    
+    // Verify Full HTML is used.
+    $this->content = drupal_render(node_view($node));
+    $this->assertRaw($html_text, 'Full HTML renders full html');
+    $form = drupal_get_form($node->type . '_node_form', $node);
+    $this->assertEqual($form['body'][LANGUAGE_NONE][0]['#format'], $full_html_format->format, 'Form offers Full HTML as default');
+
+    // Delete Full HTML, replacing it with Filtered HTML.
+    filter_format_delete($full_html_format, $filtered_html_format->format);
+    $this->content = drupal_render(node_view($node));
+    $this->assertRaw(strip_tags($html_text), 'Fallback to Filtered HTML works');
+    $form = drupal_get_form($node->type . '_node_form', $node);
+    $this->assertEqual($form['body'][LANGUAGE_NONE][0]['#format'], $filtered_html_format->format, 'Form offers Filtered HTML as default');
+
+    // Delete Filtered HTML, verify default format is used.
+    filter_format_delete($filtered_html_format);
+    $this->content = drupal_render(node_view($node));
+    $this->assertRaw(check_plain($html_text), 'Fallback to default format works');
+    $form = drupal_get_form($node->type . '_node_form', $node);
+    $this->assertEqual($form['body'][LANGUAGE_NONE][0]['#format'], filter_fallback_format(), 'Form offers fallback format as default');
+  }
+
+  /**
    * Verify that a text format is properly stored.
    */
   function verifyTextFormat($format) {
