diff options
-rw-r--r-- | modules/field/field.api.php | 13 | ||||
-rw-r--r-- | modules/field/field.crud.inc | 21 |
2 files changed, 19 insertions, 15 deletions
diff --git a/modules/field/field.api.php b/modules/field/field.api.php index 4f4fa9dc8..a06880d69 100644 --- a/modules/field/field.api.php +++ b/modules/field/field.api.php @@ -1265,17 +1265,14 @@ function hook_field_create_instance($instance) { /** * Act on a field being deleted. * - * This hook is invoked just before the field is deleted. - * - * TODO: Not implemented. + * This hook is invoked just after field is deleted. * * @param $field - * The field being deleted. + * The field just deleted. */ function hook_field_delete_field($field) { } - /** * Act on a field instance being updated. * @@ -1293,12 +1290,10 @@ function hook_field_update_instance($instance) { /** * Act on a field instance being deleted. * - * This hook is invoked just before the instance is deleted. - * - * TODO: Not implemented. + * This hook is invoked just after the instance is deleted. * * @param $instance - * The instance just updated. + * The instance just deleted. */ function hook_field_delete_instance($instance) { } diff --git a/modules/field/field.crud.inc b/modules/field/field.crud.inc index 2ce0998ce..8e0ff1497 100644 --- a/modules/field/field.crud.inc +++ b/modules/field/field.crud.inc @@ -379,15 +379,17 @@ function field_read_fields($params = array(), $include_additional = array()) { * The field name to delete. */ function field_delete_field($field_name) { + // Delete all non-deleted instances. + $field = field_info_field($field_name); + if (isset($field['bundles'])) { + foreach ($field['bundles'] as $bundle) { + field_delete_instance($field_name, $bundle); + } + } + // Mark field storage for deletion. module_invoke(variable_get('field_storage_module', 'field_sql_storage'), 'field_storage_delete_field', $field_name); - // Mark any instances of the field for deletion. - db_update('field_config_instance') - ->fields(array('deleted' => 1)) - ->condition('field_name', $field_name) - ->execute(); - // Mark the field for deletion. db_update('field_config') ->fields(array('deleted' => 1)) @@ -396,6 +398,8 @@ function field_delete_field($field_name) { // Clear the cache. field_cache_clear(TRUE); + + module_invoke_all('field_delete_field', $field); } /** @@ -683,6 +687,9 @@ function field_read_instances($params = array(), $include_additional = array()) * The bundle for the instance which will be deleted. */ function field_delete_instance($field_name, $bundle) { + // Save the instance for hook_field_delete_instance before it is deleted. + $instance = field_info_instance($field_name, $bundle); + // Mark the field instance for deletion. db_update('field_config_instance') ->fields(array('deleted' => 1)) @@ -694,6 +701,8 @@ function field_delete_instance($field_name, $bundle) { module_invoke(variable_get('field_storage_module', 'field_sql_storage'), 'field_storage_delete_instance', $field_name, $bundle); // Clear the cache. field_cache_clear(); + + module_invoke_all('field_delete_instance', $instance); } /** |