You are here

function globallink_form_entity_translation_translatable_form_submit in GlobalLink Connect for Drupal 7.6

Same name and namespace in other branches
  1. 7.7 globallink.module \globallink_form_entity_translation_translatable_form_submit()
  2. 7.5 globallink.module \globallink_form_entity_translation_translatable_form_submit()
1 string reference to 'globallink_form_entity_translation_translatable_form_submit'
globallink_form_entity_translation_translatable_form_alter in ./globallink.module

File

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

Code

function globallink_form_entity_translation_translatable_form_submit($form, &$form_state) {
  $field_name = $form_state['field']['field_name'];
  $bundle = $form_state['field']['bundles'];
  $entity_keys = array_keys($bundle);
  $entity_type = $entity_keys[0];
  $content_type = $form_state['field']['bundles'][$entity_type][0];
  $field_type = $form_state['field']['type'];
  $translatable = $form_state['field']['translatable'];
  if ($entity_type == 'taxonomy_term' || $entity_type == 'fieldable_panels_pane' || $entity_type == 'bean' || $entity_type == 'file_entity') {
    return;
  }
  if ($translatable == 0) {
    $translatable = 1;
  }
  elseif ($translatable == 1) {
    $translatable = 0;
  }
  else {
    return;
  }

  //Get translatable here
  if (!globallink_check_field_configured($content_type, $entity_type, $content_type, $field_name) && $translatable == 1) {
    if ($translatable != 1) {
      return;
    }
    if ($field_type == 'field_collection') {
      globallink_insert_fc($entity_type, $field_name, $content_type, $content_type);
    }
    else {
      $keys = array_keys($form_state['field']['bundles']);
      if (in_array('field_collection_item', $keys)) {
        $entity_type = 'field_collection_item';
        $fc_items = $form_state['field']['bundles'][$entity_type];
        foreach ($fc_items as $fc_item) {
          $ct_types = globallink_get_all_content_types_for_field($fc_item, 'field_collection');
          foreach ($ct_types as $ct_type) {
            db_insert('globallink_field_config')
              ->fields(array(
              'content_type' => $ct_type,
              'entity_type' => $entity_type,
              'bundle' => $fc_item,
              'field_name' => $field_name,
              'field_type' => $field_type,
              'field_label' => $field_name,
              'translatable' => 1,
            ))
              ->execute();
          }
        }
      }
      else {
        db_insert('globallink_field_config')
          ->fields(array(
          'content_type' => $content_type,
          'entity_type' => $entity_type,
          'bundle' => $content_type,
          'field_name' => $field_name,
          'field_type' => $field_type,
          'field_label' => $field_name,
          'translatable' => 1,
        ))
          ->execute();
      }
    }
  }
  else {
    if ($translatable == 0) {
      if ($field_type == 'field_collection') {
        globallink_delete_fc($content_type, $field_name, $entity_type, $content_type);
      }
      else {
        $keys = array_keys($form_state['field']['bundles']);
        if (in_array('field_collection_item', $keys)) {
          $entity_type = 'field_collection_item';
          $fc_items = $form_state['field']['bundles'][$entity_type];
          foreach ($fc_items as $fc_item) {
            $ct_types = globallink_get_all_content_types_for_field($fc_item, 'field_collection');
            foreach ($ct_types as $ct_type) {
              globallink_delete_fc_items($ct_type, $fc_item, $field_name, $entity_type);
            }
          }
        }
        else {
          db_delete('globallink_field_config')
            ->condition('field_name', $field_name, '=')
            ->condition('entity_type', $entity_type, '=')
            ->condition('bundle', $bundle, '=')
            ->condition('content_type', $content_type, '=')
            ->execute();
        }
      }
    }
  }
}