You are here

function eck__bundle__delete in Entity Construction Kit (ECK) 7

Same name and namespace in other branches
  1. 7.3 eck.bundle.inc \eck__bundle__delete()
  2. 7.2 eck.bundle.inc \eck__bundle__delete()

Delete the bundle of a given entity type

Parameters

$entity_type: (String) The entity type of the bundle that will be deleted

$bundle: (String) The bundle to be deleted

2 calls to eck__bundle__delete()
eck__bundle__delete_form_submit in ./eck.bundle.inc
Sumbmit function for the delete functionality
eck__entity_type__delete in ./eck.entity_type.inc
Delete the entity type

File

./eck.bundle.inc, line 244
All of the menu, pages, and forms related to bundle administration.

Code

function eck__bundle__delete($entity_type, $bundle) {

  //first delete all of the entities of this bundle
  $query = new EntityFieldQuery();
  $query
    ->entityCondition('entity_type', $entity_type->name, '=')
    ->entityCondition('bundle', $bundle->name, '=');
  $results = $query
    ->execute();
  if (!empty($results)) {
    $ids = array_keys($results[$entity_type->name]);
    entity_delete($entity_type->name, $ids);
  }

  //then we delete the bundle (field_instances)
  field_attach_delete_bundle($entity_type->name, $bundle->name);

  //and finally we delete the bundle from the eck_type table
  db_delete('eck_bundle')
    ->condition('entity_type', $entity_type->name)
    ->condition('name', $bundle->name)
    ->execute();
  menu_rebuild();
  drupal_flush_all_caches();
  drupal_set_message("The bundle '{$bundle->name}' from the entity type '{$entity_type->name}' has been deleted");

  //return "<h1>Deletion Completed</h1>

  //<h3>The bundle '{$bundle}' from the entity type '$entity_type' has been deleted<h3>";
}