You are here

function commerce_delete_instances in Commerce Core 7

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.

4 calls to commerce_delete_instances()
commerce_customer_uninstall in modules/customer/commerce_customer.install
Implements hook_uninstall().
commerce_line_item_uninstall in modules/line_item/commerce_line_item.install
Implements hook_uninstall().
commerce_order_uninstall in modules/order/commerce_order.install
Implements hook_uninstall().
commerce_product_uninstall in modules/product/commerce_product.install
Implements hook_uninstall().

File

./commerce.module, line 226
Defines features and functions common to the Commerce modules.

Code

function commerce_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) {
    commerce_delete_instance($instance);
  }
}