? MISC-FIELD-CHANGES-REAPPLY.patch
? Makefile
? d6-50-nodes.sql.gz
? d7-50-nodes-new.sql.gz
? d7-50-nodes.sql.gz
? head.kpf
? patches
? scripts/OLD-generate-autoload.pl
? scripts/generate-autoload.pl
? sites/all/cck
? sites/all/modules/color
? sites/all/modules/combofield
? sites/all/modules/devel
? sites/all/modules/pbs
? 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.53
diff -u -F '^[fc]' -r1.53 text.module
--- modules/field/modules/text/text.module	13 Apr 2010 15:16:27 -0000	1.53
+++ modules/field/modules/text/text.module	22 Apr 2010 18:43:02 -0000
@@ -590,3 +590,13 @@ function text_field_widget_error($elemen
   form_error($error_element, $error['message']);
 }
 
+/**
+ * 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();
+}
\ No newline at end of file
Index: modules/filter/filter.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/filter/filter.module,v
retrieving revision 1.327
diff -u -F '^[fc]' -r1.327 filter.module
--- modules/filter/filter.module	13 Apr 2010 15:23:03 -0000	1.327
+++ modules/filter/filter.module	22 Apr 2010 18:43:03 -0000
@@ -149,15 +149,52 @@ function _filter_delete_format_access($f
 }
 
 /**
+ * Set the replacement format for a deleted format.
+ *
+ * @param $format_id
+ *   A format that is deleted.
+ * @param $replacement_id
+ *   The replacement format for $format_id.
+ */
+function _filter_set_replacement_format($format_id, $replacement_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());
+  if (isset($deleted[$format_id])) {
+    return $deleted[$format_id];
+  }
+  return $format_id;
+}
+
+/**
  * Load a text format object from the database.
  *
  * @param $format_id
  *   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;
 }
@@ -269,8 +306,14 @@ function filter_format_delete($format) {
     ->condition('format', $format->format)
     ->execute();
 
-  // Allow modules to react on text format deletion.
+  // Determine the replacement format, which for now is always the
+  // site's fallback format.
   $fallback = filter_format_load(filter_fallback_format());
+
+  // Update the deleted-formats 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();
@@ -831,6 +874,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'),
