You are here

function globallink_form_field_ui_field_overview_form_submit in GlobalLink Connect for Drupal 7.5

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

Submit handler for Manage Fields Page of Content Type and Field Collection. Adds a new field being added to the fields config table for translation.

1 string reference to 'globallink_form_field_ui_field_overview_form_submit'
globallink_form_field_ui_field_overview_form_alter in ./globallink.module
Implements hook_form_FORM_ID_alter().

File

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

Code

function globallink_form_field_ui_field_overview_form_submit(&$form, &$form_state) {
  $entity_type = isset($form['#entity_type']) ? $form['#entity_type'] : FALSE;
  $bundle = isset($form['#bundle']) ? $form['#bundle'] : FALSE;
  $new_field = isset($form['fields']['_add_new_field']) ? $form['fields']['_add_new_field'] : FALSE;
  $existing_field = isset($form['fields']['_add_existing_field']) ? $form['fields']['_add_existing_field'] : FALSE;
  if (!$entity_type) {
    return;
  }
  switch ($entity_type) {
    case 'node':
      if (!globallink_translation_supported($bundle)) {
        break;
      }

      // Request coming from Manage Fields of Content Type
      if ($new_field && isset($new_field['type']['#value'])) {
        switch ($new_field['type']['#value']) {
          case 'list_boolean':
          case 'image':
          case 'file':
          case 'taxonomy_term_reference':
            break;
          case 'field_collection':

            // New field-collection added, just add the empty field-collection to config
            $new_field_name = $new_field['field_name']['#value'];
            if ($new_field_name != '') {
              db_insert('globallink_field_config')
                ->fields(array(
                'content_type' => $bundle,
                'entity_type' => $entity_type,
                'bundle' => $bundle,
                'field_name' => 'field_' . $new_field_name,
                'field_type' => $new_field['type']['#value'],
                'field_label' => $new_field['label']['#value'],
                'translatable' => 1,
              ))
                ->execute();
            }
            break;
          default:

            // Regular New field, just add to config
            $new_field_name = $new_field['field_name']['#value'];
            if ($new_field_name != '') {
              db_insert('globallink_field_config')
                ->fields(array(
                'content_type' => $bundle,
                'entity_type' => $entity_type,
                'bundle' => $bundle,
                'field_name' => 'field_' . $new_field_name,
                'field_type' => $new_field['type']['#value'],
                'field_label' => $new_field['label']['#value'],
                'translatable' => 1,
              ))
                ->execute();
            }
        }
      }
      if (!$existing_field || !isset($existing_field['field_name']['#value'])) {
        break;
      }

      // Existing field is being added to this content type
      $existing_field_name = $existing_field['field_name']['#value'];
      if ($existing_field_name == '') {
        break;
      }
      $existing_field_info = field_info_field($existing_field_name);
      switch ($existing_field_info['type']) {
        case 'list_boolean':
        case 'image':
        case 'file':
        case 'taxonomy_term_reference':
          break;
        case 'field_collection':

          // Existing FC being added to this content type
          // Add FC and all the FC fields recursively to the config
          globallink_insert_fc($entity_type, $existing_field_name, $bundle, $bundle);
          break;
        default:

          // Regular existing field, just add to config
          $existing_field_instance = field_info_instance($entity_type, $existing_field_name, $bundle);
          db_insert('globallink_field_config')
            ->fields(array(
            'content_type' => $bundle,
            'entity_type' => $entity_type,
            'bundle' => $bundle,
            'field_name' => $existing_field_name,
            'field_type' => $existing_field_info['type'],
            'field_label' => $existing_field_instance['label'],
            'translatable' => 1,
          ))
            ->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
      $fc_name = $bundle;
      if ($new_field && isset($new_field['type']['#value'])) {

        // A new field is being added to this field-collection
        switch ($new_field['type']['#value']) {
          case 'list_boolean':
          case 'image':
          case 'file':
          case 'taxonomy_term_reference':
            break;
          default:

            // Regular new field is being added to this field-collection, just add to config
            $new_field_name = $new_field['field_name']['#value'];
            if ($new_field_name == '') {
              break;
            }

            // First get all the content types for this field-collection from config,
            // then add this field for all the content types in the config
            $content_types = globallink_get_all_content_types_for_field($fc_name, 'field_collection');
            foreach ($content_types as $content_type) {
              db_insert('globallink_field_config')
                ->fields(array(
                'content_type' => $content_type,
                'entity_type' => $entity_type,
                'bundle' => $fc_name,
                'field_name' => 'field_' . $new_field_name,
                'field_type' => $new_field['type']['#value'],
                'field_label' => $new_field['label']['#value'],
                'translatable' => 1,
              ))
                ->execute();
            }
        }
      }
      if (!$existing_field || !isset($existing_field['field_name']['#value'])) {
        break;
      }

      // Existing field is being added to this field-collection
      $existing_field_name = $existing_field['field_name']['#value'];
      if ($existing_field_name == '') {
        break;
      }
      $existing_field_info = field_info_field($existing_field_name);
      switch ($existing_field_info['type']) {
        case 'list_boolean':
        case 'image':
        case 'file':
        case 'taxonomy_term_reference':
          break;
        case 'field_collection':

          // If existing field-collection is added to the field-collection, then add fields recursively
          $content_types = globallink_get_all_content_types_for_field($fc_name, 'field_collection');

          // First get all the content types for this field-collection from config
          // then add this field for all the content types in the config
          foreach ($content_types as $content_type) {
            globallink_insert_fc($entity_type, $existing_field_name, $content_type, $fc_name);
          }
          break;
        default:

          // First get all the content types for this field-collection from config
          // then add this field for all the content types in the config
          $content_types = globallink_get_all_content_types_for_field($fc_name, 'field_collection');
          foreach ($content_types as $content_type) {
            $existing_field_instance = field_info_instance($entity_type, $existing_field_name, $bundle);
            db_insert('globallink_field_config')
              ->fields(array(
              'content_type' => $content_type,
              'entity_type' => $entity_type,
              'bundle' => $fc_name,
              'field_name' => $existing_field_name,
              'field_type' => $existing_field_info['type'],
              'field_label' => $existing_field_instance['label'],
              'translatable' => 1,
            ))
              ->execute();
          }
      }
      break;
  }
}