Can't delete entities using entity_delete_multiple() I was studying how  to work with entities following http://www.bluespark.com/blog/drupal-entities-part-3-programming-hello-drupal-entity.

I downloaded the module, created by the author of that article. Then I wanted to delete entities, using the following code.

entity_delete_multiple('basic', array(1,4) );


But it didn't delete anything. I though that the delete method should be implemented, and added it into the class.

class BasicController extends DrupalDefaultEntityController{

  public function delete($basic) {
    var_dump(1);exit;
    db_delete('basic')
      -&gt;condition('basic_id', $basic-&gt;basic_id, '=')
      -&gt;execute();
    field_attach_update('basic', $basic);
    module_invoke_all('entity_delete', 'basic', $basic);
  }
};


It doesn't work: 1 is not printed.

How do I delete an entity with fields?
entity_delete_multiple() is implemented by the Entity API module, which is not part of Drupal.

In order to be able to delete entities with entity_delete_multiple() you need to do one of two things.


Define a deletion callback for your entity
Use a controller class that implements EntityAPIControllerInterface


In fact, this is the code used by entity_delete_multiple().

function entity_delete_multiple($entity_type, $ids) {
  $info = entity_get_info($entity_type);
  if (isset($info['deletion callback'])) {
    foreach ($ids as $id) {
      $info['deletion callback']($id);
    }
  }
  elseif (in_array('EntityAPIControllerInterface', class_implements($info['controller class']))) {
    entity_get_controller($entity_type)-&gt;delete($ids);
  }
  else {
    return FALSE;
  }
}


In the first case, you simply define a function similar to the following.

function basic_delete_entity($id) {
  // Delete the entity whose ID is $id.
}


You can use any name for the delete callback, as long as you refer it in your hook_entity_info().

In the second case, you normally sub class EntityAPIController. EntityAPIController::delete() should normally be sufficient.