You are here

public function EntityLegalDocumentController::delete in Entity Legal 7

Same name and namespace in other branches
  1. 7.2 entity_legal.entity_controller.inc \EntityLegalDocumentController::delete()

Overridden to care about reverted entities.

Overrides EntityAPIControllerExportable::delete

File

./entity_legal.entity_controller.inc, line 52
Entity API controller classes for entity_legal module.

Class

EntityLegalDocumentController
Entity Legal Document controller class.

Code

public function delete($ids, DatabaseTransaction $transaction = NULL) {

  // Delete all associated versions.
  foreach ($ids as $document_name) {
    $version_query = new EntityFieldQuery();
    $version_query
      ->entityCondition('entity_type', ENTITY_LEGAL_DOCUMENT_VERSION_ENTITY_NAME)
      ->propertyCondition('document_name', $document_name);
    $version_result = $version_query
      ->execute();
    if (!empty($version_result) && !empty($version_result[ENTITY_LEGAL_DOCUMENT_VERSION_ENTITY_NAME])) {
      foreach (array_keys($version_result[ENTITY_LEGAL_DOCUMENT_VERSION_ENTITY_NAME]) as $version_name) {
        entity_delete(ENTITY_LEGAL_DOCUMENT_VERSION_ENTITY_NAME, $version_name);
      }
    }

    // Delete field instance.
    $instances = field_read_instances(array(
      'entity_type' => 'entity_legal_document_version',
      'bundle' => $document_name,
    ), array(
      'include_inactive' => FALSE,
      'include_deleted' => FALSE,
    ));
    foreach ($instances as $instance) {
      field_delete_instance($instance, FALSE);
    }
  }
  parent::delete($ids, $transaction);
}