You are here

function merci_core_delete_instances in MERCI (Manage Equipment Reservations, Checkout and Inventory) 7.3

Deletes any field instance attached to entities of the specified type, regardless of whether or not the field is active.

Parameters

$entity_type: The type of entity whose fields should be deleted.

$bundle: Optionally limit instance deletion to a specific bundle of the specified entity type.

2 calls to merci_core_delete_instances()
merci_hours_uninstall in merci_hours/merci_hours.install
Implements hook_uninstall().
merci_restrictions_uninstall in merci_restrictions/merci_restrictions.install
Implements hook_uninstall().

File

merci_core/merci_core.module, line 449

Code

function merci_core_delete_instances($entity_type, $bundle = NULL) {

  // Prepare a parameters array to load the specified instances.
  $params = array(
    'entity_type' => $entity_type,
  );
  if (!empty($bundle)) {
    $params['bundle'] = $bundle;

    // Delete this bundle's field bundle settings.
    variable_del('field_bundle_settings_' . $entity_type . '__' . $bundle);
  }
  else {

    // Delete all field bundle settings for this entity type.
    db_delete('variable')
      ->condition('name', db_like('field_bundle_settings_' . $entity_type . '__') . '%', 'LIKE')
      ->execute();
  }

  // Read and delete the matching field instances.
  foreach (field_read_instances($params, array(
    'include_inactive' => TRUE,
  )) as $instance) {
    merci_core_delete_instance($instance);
  }
}