You are here

function commerce_delete_instance in Commerce Core 7

Deletes the specified instance and handles field cleanup manually in case the instance is of a disabled field.

Parameters

$instance: The field instance info array to be deleted.

1 call to commerce_delete_instance()
commerce_delete_instances in ./commerce.module
Deletes any field instance attached to entities of the specified type, regardless of whether or not the field is active.

File

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

Code

function commerce_delete_instance($instance) {

  // First activate the instance's field if necessary.
  $field_name = $instance['field_name'];
  $activated = commerce_activate_field($field_name);

  // Clear the field cache if we just activated the field.
  if ($activated) {
    field_cache_clear();
  }

  // Then delete the instance.
  field_delete_instance($instance, FALSE);

  // Now check to see if there are any other instances of the field left.
  $field = field_info_field($field_name);
  if (count($field['bundles']) == 0) {
    field_delete_field($field_name);
  }
  elseif ($activated) {

    // If there are remaining instances but the field was originally disabled,
    // disabled it again now.
    $field['active'] = 0;
    field_update_field($field);
  }
}