1. drupal
    1. 8
    2. 7
8 – 7 field_delete_instance($instance, $field_cleanup = TRUE)

Marks a field instance and its data for deletion.


$instance An instance structure.

$field_cleanup If TRUE, the field will be deleted as well if its last instance is being deleted. If FALSE, it is the caller's responsibility to handle the case of fields left without instances. Defaults to TRUE.

Related topics

▾ 9 functions call field_delete_instance()

CommentFieldsTest::testCommentDefaultFields in modules/comment/comment.test
Tests that the default 'comment_body' field is correctly added.
FieldBulkDeleteTestCase::testDeleteFieldInstance in modules/field/tests/field.test
Verify that deleting an instance leaves the field data items in the database and that the appropriate Field API functions can operate on the deleted data and instance.
FieldBulkDeleteTestCase::testPurgeField in modules/field/tests/field.test
Verify that fields are preserved and purged correctly as multiple instances are deleted and purged.
FieldBulkDeleteTestCase::testPurgeInstance in modules/field/tests/field.test
Verify that field data items and instances are purged when an instance is deleted.
FieldInstanceCrudTestCase::testDeleteFieldInstance in modules/field/tests/field.test
Test the deletion of a field instance.
field_attach_delete_bundle in modules/field/
Notify field.module the a bundle was deleted.
field_delete_field in modules/field/
Marks a field and its instances and data for deletion.
field_ui_field_delete_form_submit in modules/field_ui/
Removes a field instance from a bundle.
node_example_uninstall in examples/node_example/node_example.install
Implements hook_uninstall().


modules/field/, line 733

function field_delete_instance($instance, $field_cleanup = TRUE) {
  // Mark the field instance for deletion.
    ->fields(array('deleted' => 1))
    ->condition('field_name', $instance['field_name'])
    ->condition('entity_type', $instance['entity_type'])
    ->condition('bundle', $instance['bundle'])

  // Clear the cache.

  // Mark instance data for deletion.
  $field = field_info_field($instance['field_name']);
  module_invoke($field['storage']['module'], 'field_storage_delete_instance', $instance);

  // Let modules react to the deletion of the instance.
  module_invoke_all('field_delete_instance', $instance);

  // Delete the field itself if we just deleted its last instance.
  if ($field_cleanup && count($field['bundles']) == 0) {