You are here

function globallink_form_field_ui_field_delete_form_submit in GlobalLink Connect for Drupal 7.6

Same name and namespace in other branches
  1. 7.7 globallink.module \globallink_form_field_ui_field_delete_form_submit()
  2. 7.5 globallink.module \globallink_form_field_ui_field_delete_form_submit()

Submit handler for delete link on Manage Fields Page of Content Type and Field Collection. This deletes a field from fields config table.

1 string reference to 'globallink_form_field_ui_field_delete_form_submit'
globallink_form_field_ui_field_delete_form_alter in ./globallink.module
Implements hook_form_FORM_ID_alter().

File

./globallink.module, line 75
GlobalLink translation module.

Code

function globallink_form_field_ui_field_delete_form_submit($form, &$form_state) {
  $entity_type = isset($form['entity_type']['#value']) ? $form['entity_type']['#value'] : FALSE;
  $bundle_name = isset($form['bundle']['#value']) ? $form['bundle']['#value'] : FALSE;
  $field_name = isset($form['field_name']['#value']) ? $form['field_name']['#value'] : FALSE;
  if (!$entity_type) {
    return;
  }
  switch ($entity_type) {
    case 'node':

      // Request coming from Manage Fields of Content Type
      $field_info = field_info_field($field_name);
      switch ($field_info['type']) {
        case 'list_boolean':
        case 'list_integer':
        case 'file':
        case 'taxonomy_term_reference':
          break;
        case 'field_collection':

          // field-collection being deleted, delete all fields recursively for this content type only
          globallink_delete_fc($bundle_name, $field_name, $entity_type, $bundle_name);
          break;
        default:

          // Regular field, just delete from the config
          db_delete('globallink_field_config')
            ->condition('content_type', $bundle_name, ' = ')
            ->condition('entity_type', $entity_type, ' = ')
            ->condition('bundle', $bundle_name, ' = ')
            ->condition('field_name', $field_name, ' = ')
            ->execute();
          break;
      }
      break;
    case 'field_collection_item':

      // Request coming from Manage Fields of Field Collections
      // Entity type for all the fields here will be field_collection_item
      $field_info = field_info_field($field_name);
      switch ($field_info['type']) {
        case 'list_boolean':
        case 'image':
        case 'file':
        case 'taxonomy_term_reference':
          break;
        case 'field_collection':

          // Field-collection being deleted, delete all fields recursively for all the content types
          $content_types = globallink_get_all_content_types_for_field($bundle_name, 'field_collection');
          foreach ($content_types as $content_type) {
            globallink_delete_fc($content_type, $field_name, $entity_type, $bundle_name);
          }
          break;
        default:

          // Regular field-collection field, just delete from the config for all content types
          $content_types = globallink_get_all_content_types_for_field($bundle_name, 'field_collection');
          foreach ($content_types as $content_type) {
            db_delete('globallink_field_config')
              ->condition('content_type', $content_type, ' = ')
              ->condition('entity_type', $entity_type, ' = ')
              ->condition('bundle', $bundle_name, ' = ')
              ->condition('field_name', $field_name, ' = ')
              ->execute();
          }
      }
      break;
  }
}