You are here

public static function FieldHelper::purgeInstance in Helper 7

1 call to FieldHelper::purgeInstance()
FieldHelper::deleteInstance in lib/FieldHelper.php
Delete a field instance.

File

lib/FieldHelper.php, line 268

Class

FieldHelper

Code

public static function purgeInstance(array $instance) {
  $field = static::readFieldByID($instance['field_id']);
  $instance = static::readInstanceById($instance['id']);
  if (empty($instance['deleted'])) {
    throw new FieldException("Field instance not yet marked as deleted.");
  }
  if (!module_exists($field['storage']['module'])) {
    throw new FieldException("The {$field['storage']['module']} module needs to be enabled in order to delete an instance ID {$instance['id']} from field ID {$field['id']}.");
  }
  db_delete('field_config_instance')
    ->condition('id', $instance['id'])
    ->execute();

  // Notify the storage engine.
  module_invoke($field['storage']['module'], 'field_storage_purge_instance', $instance);

  // Clear the cache.
  field_info_cache_clear();

  // Invoke external hooks after the cache is cleared for API consistency.
  module_invoke_all('field_purge_instance', $instance);
  watchdog('helper', "Field instance ID {$instance['id']} completely removed.");
}