7.x field.crud.inc field_delete_field($field_name)

Marks a field and its instances and data for deletion.


$field_name: The field name to delete.

Related topics

9 calls to field_delete_field()
comment_uninstall in modules/comment/comment.install
Implements hook_uninstall().
FieldCrudTestCase::testDeleteField in modules/field/tests/field.test
Test the deletion of a field.
field_delete_instance in modules/field/field.crud.inc
Marks a field instance and its data for deletion.
FileFieldValidateTestCase::testFileExtension in modules/file/tests/file.test
Tests file extension checking.
FileFieldValidateTestCase::testFileMaxSize in modules/file/tests/file.test
Tests the max file size validator.

... See full list


modules/field/field.crud.inc, line 411
Field CRUD API, handling field and field instance creation and deletion.


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 $entity_type => $bundles) {
      foreach ($bundles as $bundle) {
        $instance = field_info_instance($entity_type, $field_name, $bundle);
        field_delete_instance($instance, FALSE);

  // Mark field data for deletion.
  module_invoke($field['storage']['module'], 'field_storage_delete_field', $field);

  // Mark the field for deletion.
    'deleted' => 1,
    ->condition('field_name', $field_name)

  // Clear the cache.
  module_invoke_all('field_delete_field', $field);


berenddeboer’s picture

Use field_purge_batch() to actually delete the field.

Benone_’s picture

Thumb up mate;)

freeduck’s picture

Use field_purge_batch() to actually delete the field.

Or run cron manually.

liquidcms’s picture

cron didn't do the trick; field_purge_batch() did.

Elijah Lynn’s picture

Same here, drush cron did not work but field_purge_batch(100) did.

Elijah Lynn’s picture

Wow, I just came across this again via Google. drush cron won't work right away because it only runs X at a time, it would eventually work if you ran it enough.

Elijah Lynn’s picture

Also, note to self. I ran field_purge_batch(100) and was getting errors after a field_collection to multifield conversion. For some reason, if you run it with field_purge_batch(0) then it works fine, just like drush cron would invoke it via field_cron.

btopro’s picture

https://api.drupal.org/comment/62433#comment-62433 nte about calling twice if in hook_update_N

doub1ejack’s picture

Is there any way to confirm deletion?

drupalshrek’s picture

You can confirm the field has been deleted by looking at:

Dane Powell’s picture

This function does not exist in D8, something like this might work instead:

$field = FieldStorageConfig::loadByName($entity_type, $field_name);

You may then need to wait for cron to run to actually purge the field from the DB.

benjifisher’s picture

The change record for D8 is here: https://www.drupal.org/node/2012896

If you are going to delete the field storage, then I think you also want to delete the corresponding fields. (IIUC, field/field instance in D7 becomes field storage/field in D8.)

liquidcms’s picture

Any idea how to do that?