function field_entity_bundle_delete

Implements hook_entity_bundle_delete().

This deletes the data for the field instances as well as the field instances themselves. This function actually just marks the data and field instances as deleted, leaving the garbage collection for a separate process, because it is not always possible to delete this much data in a single page request (particularly since for some field types, the deletion is more than just a simple DELETE query).

Related topics

File

drupal/core/modules/field/field.attach.inc, line 1586
Field attach API, allowing entities (nodes, users, ...) to be 'fieldable'.

Code

function field_entity_bundle_delete($entity_type, $bundle) {

  // Get the instances on the bundle. field_read_instances() must be used
  // here since field_info_instances() does not return instances for disabled
  // entity types or bundles.
  $instances = field_read_instances(array(
    'entity_type' => $entity_type,
    'bundle' => $bundle,
  ), array(
    'include_inactive' => TRUE,
  ));
  foreach ($instances as $instance) {
    field_delete_instance($instance);
  }

  // Clear the cache.
  field_cache_clear();

  // Clear bundle display settings.
  variable_del('field_bundle_settings_' . $entity_type . '__' . $bundle);
}