You are here

function content_field_instance_delete in Content Construction Kit (CCK) 6

Same name and namespace in other branches
  1. 5 content_crud.inc \content_field_instance_delete()
  2. 6.3 includes/content.crud.inc \content_field_instance_delete()
  3. 6.2 includes/content.crud.inc \content_field_instance_delete()

Delete an existing field instance.

4 calls to content_field_instance_delete()
ContentCrudTestCase::deleteField in tests/content.crud.test
Deletes an instance of a field.
content_module_delete in includes/content.crud.inc
Delete all data related to a module.
content_type_delete in includes/content.crud.inc
Make changes needed when a content type is deleted.
_content_admin_field_remove_submit in includes/content.admin.inc
Remove a field from a content type.

File

includes/content.crud.inc, line 474
Create/Read/Update/Delete functions for CCK-defined object types.

Code

function content_field_instance_delete($field_name, $type_name) {
  include_once './' . drupal_get_path('module', 'content') . '/includes/content.admin.inc';

  // Get the previous field value.
  $field = array_pop(content_field_instance_read(array(
    'field_name' => $field_name,
    'type_name' => $type_name,
  )));

  // Invoke hook_content_fieldapi().
  module_invoke_all('content_fieldapi', 'delete instance', $field);
  db_query("DELETE FROM {" . content_instance_tablename() . "} WHERE field_name = '%s' AND type_name = '%s'", $field['field_name'], $field['type_name']);

  // If no instances remain, delete the field entirely.
  $instances = content_field_instance_read(array(
    'field_name' => $field_name,
  ));
  if (sizeof($instances) < 1) {
    db_query("DELETE FROM {" . content_field_tablename() . "} WHERE field_name = '%s'", $field['field_name']);

    // Deleted fields require a menu rebuild to remove all the field paths.
    content_menu_needs_rebuild(TRUE);
  }

  // If only one instance remains, we may need to change the database
  // representation for this field.
  if (sizeof($instances) == 1 && !$field['multiple']) {

    // Multiple-valued fields are always stored per-field-type.
    $instance = $instances[0];
    $new_instance = $instance;
    $new_instance['db_storage'] = CONTENT_DB_STORAGE_PER_CONTENT_TYPE;
    _content_field_write($new_instance, 'update');
    content_alter_schema($instance, $new_instance);
  }
  content_clear_type_cache(TRUE);
  return $field;
}