Change record status: 
Project: 
Introduced in branch: 
7.x
Description: 

When there is field data in place, there is a de-facto dependency of the field system as a whole on field type modules - if that module is disabled, it is has no idea what to do with the data until the module is re-enabled again (and other actions while the module is disabled, like deleting bundles or instances can complicate this too).

The patch in #943772 uses hook_system_info_alter() to make this dependency explicit - i.e. by making those field type modules required in the UI, with an explanatory note.

With the proposed solution, a module which both defines and implements a field type can not delete its fields on uninstall. Therefore, the solution is "Don't do that." Instead, the field type should be defined in a helper module which the implementation module depends on.

For example:

  1. foo_field.module implements hook_field_info() to define a field type foo_type.
  2. foo.module depends on foo_field.module.
  3. When a user installs foo.module, foo_install() calls field_create_field(array('field_name' => 'foo', 'field_type' => 'foo_type')).
  4. When the user uninstalls foo.module, foo_uninstall() calls field_delete_field('foo'), and its fields are marked for deletion.
  5. The field values get purged on subsequent cron runs.
  6. After the purge is completed, the user can uninstall foo_field.module.

@todo: For an already-installed module which has violated the "don't do that" rule above, describe how to manually remove data so that the module can be uninstalled.

Experimental module that provides an "orphaned fields" report:

http://drupal.org/sandbox/Mile23/1171894

Related issues:

#1199946: Disabled modules are broken beyond repair so the "disable" functionality needs to be removed

#943772: field_delete_field() and others fail for inactive fields

#1029606: Regression: Not loading the .module file causes a fatal error when uninstalling some modules (as does loading it)

#1115510: Entity providing modules must call field_attach_delete_bundle() in hook_uninstall()

#773828: Upgrade of disabled modules fails

#895014: All fields of a node type are lost on module disable

#1017672: D6 to D7 update process permanently deletes comment bodies and other data, and throws fatal SQL errors

#1264728: Refresh field 'active' state in module_enable() / _disable()

#1264756: Inline field purge within field_delete_field()

#1288276: The status page should warn when two different types of field hooks are implemented by the same module.

Impacts: 
Site builders, administrators, editors
Module developers
Updates Done (doc team, etc.)
Online documentation: 
Not done
Theming guide: 
Not done
Module developer documentation: 
Not done
Examples project: 
Not done
Coder Review: 
Not done
Coder Upgrade: 
Not done
Other: 
Other updates done

Comments

  1. Go to your database and open the "field_config" table.
  2. Replace all entries that have the field types you want to remove to have type "text" and module "text"
  3. Now you can uninstall your module, the custom field tables will be automatically removed.

As you uninstall your module you will probably see some some error messages thrown by the text module, you can safely ignore these.