You are here

function lingotek_admin_entity_bundle_profiles_form_submit in Lingotek Translation 7.6

Same name and namespace in other branches
  1. 7.7 lingotek.admin.inc \lingotek_admin_entity_bundle_profiles_form_submit()
  2. 7.5 lingotek.admin.inc \lingotek_admin_entity_bundle_profiles_form_submit()

Node Translation Settings - Form Submit

2 calls to lingotek_admin_entity_bundle_profiles_form_submit()
lingotek_setup_comment_translation_settings_form_submit in ./lingotek.setup.inc
lingotek_setup_node_translation_settings_form_submit in ./lingotek.setup.inc
Node Translation Settings - Form Submit
1 string reference to 'lingotek_admin_entity_bundle_profiles_form_submit'
lingotek_admin_entity_bundle_profiles_form in ./lingotek.admin.inc
Content translation form

File

./lingotek.admin.inc, line 495

Code

function lingotek_admin_entity_bundle_profiles_form_submit($form, &$form_state) {
  $entity_type = $form_state['input']['entity_type'];
  if (isset($form_state['values']['lingotek_nodes_translation_method'])) {
    variable_set('lingotek_nodes_translation_method', $form_state['values']['lingotek_nodes_translation_method']);
  }
  $enabled_fields = variable_get('lingotek_enabled_fields', array());

  // Reset fields for the entity type but leave its existence there
  $enabled_fields[$entity_type] = array();
  $operations = array();
  $entity_profiles = variable_get('lingotek_entity_profiles', array());
  $field_collection_field_types = field_read_fields(array(
    'type' => 'field_collection',
  ));
  $field_based_translation = variable_get('lingotek_nodes_translation_method') == 'field' ? TRUE : FALSE;
  foreach ($form_state['input'] as $key => $value) {

    // Look for Selected Content Types and Fields.
    if (FALSE !== strpos($key, '_SEPERATOR_')) {

      // And only if set to translate
      if ($value != 0) {
        $parts = explode('_SEPERATOR_', $key);
        $content_type = $parts[0];
        $content_field = $parts[1];

        //check to make sure that the content type is enabled
        if ($form_state['input']['profile_' . $content_type] != LingotekSync::PROFILE_DISABLED) {
          $enabled_fields[$entity_type][$content_type][] = $content_field;

          // Set this content type to be translation-enabled only if currently disabled.
          $currently_enabled_content_type = variable_get('language_content_type_' . $content_type, '0');
          if ($currently_enabled_content_type == '0') {
            variable_set('language_content_type_' . $content_type, '1');
          }

          // Set this field to 'translatable' if using field-based translation.
          if ($field_based_translation) {

            // Update the field via the Field API (Instead of the direct db_update)
            $field = field_info_field($content_field);
            $is_field_collection = key_exists($content_field, $field_collection_field_types);
            $field['translatable'] = $is_field_collection ? 0 : 1;
            field_update_field($field);
          }
        }
      }
    }

    // END:  Selected Content Types and Fields
    // Look for any nodes we need to do the Title swap for.
    if (FALSE !== strpos($key, 'title_swap_')) {

      // And only if set to swap
      if ($value != 0) {
        $content_type = substr($key, strlen('title_swap_'));
        $field_array = explode('_', $content_type);
        $legacy_field = array_pop($field_array);
        $content_type = implode('_', $field_array);

        //check to make sure that the content type is enabled
        if ($form_state['input']['profile_' . $content_type] != LingotekSync::PROFILE_DISABLED) {

          // Do the actual title replacement
          $bundle = $content_type;

          // Use the Title module to migrate the content.
          if (title_field_replacement_toggle($entity_type, $bundle, $legacy_field)) {

            //title_field_replacement_batch_set($title_entity, $title_bundle, $title_field);
            $operations[] = array(
              'title_field_replacement_batch',
              array(
                $entity_type,
                $bundle,
                $legacy_field,
              ),
            );
            $field_name = $legacy_field . '_field';
            $enabled_fields[$entity_type][$content_type][] = $field_name;
            $field = field_info_field($field_name);
            $is_field_collection = key_exists($field_name, $field_collection_field_types);
            if ($field_based_translation && !$is_field_collection) {
              $operations[] = array(
                'field_update_field',
                array(
                  $field,
                ),
              );

              //field_update_field($field);
            }
          }
        }
      }
    }

    // Look for any profiles
    if (FALSE !== strpos($key, 'profile_')) {
      $content_type = substr($key, strlen('profile_'));
      $entity_profiles[$entity_type][$content_type] = $value;
      variable_set('lingotek_entity_profiles', $entity_profiles);
    }

    // Look for any prepare/cleanup functions to record for future running
    if (FALSE !== strpos($key, 'lingotek_function')) {

      // Add the preference for future reference in settings.
      variable_set($key, $value);
      if ($value) {
        lingotek_set_batch_function($key);
      }
    }
  }
  $_SESSION['lingotek_setup_path'][] = lingotek_get_entity_setup_path($entity_type);
  variable_set('lingotek_enabled_fields', $enabled_fields);
  drupal_set_message(t('Your content types have been updated.'));

  // This is needed for versions of Drupal core 7.10 and lower. See http://drupal.org/node/1380660 for details.
  drupal_static_reset('field_available_languages');
  if (count($operations)) {
    $batch = array(
      'title' => t('Preparing content for translation'),
      'operations' => $operations,
    );
    batch_set($batch);
  }
  if (batch_get()) {

    // Reverse the order of the batches in order to put title manipulations before language prep
    $final_batch_set =& batch_get();
    $final_batch_set['sets'] = array_reverse($final_batch_set['sets']);

    // if coming from the settings page, stay there; otherwise, continue with setup pages
    $cur_path = current_path();
    if ($cur_path == 'admin/settings/lingotek/settings' || $cur_path == LINGOTEK_MENU_LANG_BASE_URL . '/settings') {
      $redirect = $cur_path;
    }
    else {
      $redirect = lingotek_get_entity_setup_path($entity_type, TRUE);
    }
    batch_process($redirect);
  }
}