1 entity_example.inc public EntityExampleBasicController::deleteMultiple($entities)

Delete one or more entity_example_basic entities.

Deletion is unfortunately not supported in the base BackdropDefaultEntityController class.

Parameters

array $entities: An array of entity IDs or a single numeric ID.

File

modules/examples/entity_example/entity_example.inc, line 158

Class

EntityExampleBasicController
EntityExampleBasicController extends BackdropDefaultEntityController.

Code

public function deleteMultiple($entities) {
  $basic_ids = array();
  if (!empty($entities)) {
    $transaction = db_transaction();
    try {
      foreach ($entities as $entity) {
        // Invoke hook_entity_delete().
        module_invoke_all('entity_delete', $entity, 'entity_example_basic');
        field_attach_delete('entity_example_basic', $entity);
        $basic_ids[] = $entity->basic_id;
      }
      db_delete('entity_example_basic')
        ->condition('basic_id', $basic_ids, 'IN')
        ->execute();
    }
    catch (Exception $e) {
      $transaction->rollback();
      watchdog_exception('entity_example', $e);
      throw $e;
    }
  }
}