function drush_field_delete

8.0.x field.drush.inc drush_field_delete($field_name)
6.x field.drush.inc drush_field_delete($field_name)
7.x field.drush.inc drush_field_delete($field_name)
4.x field.drush.inc drush_field_delete($field_name)
5.x field.drush.inc drush_field_delete($field_name)

File

commands/core/field.drush.inc, line 220
Field API's drush integration

Code

function drush_field_delete($field_name) {
  $info = field_info_field($field_name);
  $confirm = TRUE;

  if (!$bundle = drush_get_option('bundle')) {
    foreach ($info['bundles'] as $entity_type => $bundles) {
      foreach ($bundles as $bundle) {
        $all_bundles[] = $bundle;
      }
    }
    if (count($all_bundles) > 1) {
      $options = array_merge(array('all' => dt('All bundles')), array_combine($all_bundles, $all_bundles));
      $bundle = drush_choice($options, dt("Choose a particular bundle or 'All bundles'"));
      if (!$bundle) {
        return drush_user_abort();
      }
      $confirm = FALSE;
    }
    else {
      if (!drush_confirm(dt('Do you want to delete the !field_name field?', array('!field_name' => $field_name)))) {
        return drush_user_abort();
      }
    }
  }

  if ($bundle == 'all') {
    foreach ($info['bundles'] as $entity_type => $bundles) {
      foreach ($bundles as $bundle) {
        $instance = field_info_instance($entity_type, $field_name, $bundle);
        drush_op('field_delete_instance', $instance);
      }
    }
  }
  else {
    $entity_type = drush_field_get_entity_from_bundle($bundle);
    $instance = field_info_instance($entity_type, $field_name, $bundle);
    drush_op('field_delete_instance', $instance);
  }

  // If there are no more bundles, delete the field.
  $info = field_info_field($field_name);
  if (empty($info['bundles'])) {
    drush_op('field_delete_field', $field_name);
  }
}