You are here

function lingotek_setup_node_translation_settings_form in Lingotek Translation 7.2

Same name and namespace in other branches
  1. 7.7 lingotek.setup.inc \lingotek_setup_node_translation_settings_form()
  2. 7.3 lingotek.setup.inc \lingotek_setup_node_translation_settings_form()
  3. 7.4 lingotek.setup.inc \lingotek_setup_node_translation_settings_form()
  4. 7.5 lingotek.setup.inc \lingotek_setup_node_translation_settings_form()
  5. 7.6 lingotek.setup.inc \lingotek_setup_node_translation_settings_form()

Node Translation Settings - Form Layout Select the Content Types and Fields to be Translated.

1 string reference to 'lingotek_setup_node_translation_settings_form'
lingotek_menu in ./lingotek.module
Implements hook_menu().

File

./lingotek.setup.inc, line 597
Lingotek Easy Install Process.

Code

function lingotek_setup_node_translation_settings_form($form, $form_state) {
  $raw_types = node_type_get_types();
  $types = array();
  $translate = variable_get('lingotek_translate_fields', array());
  if (count($translate) > 0) {
    $use_defaults = FALSE;
  }
  else {
    $use_defaults = TRUE;
  }

  // What types of fields DO we translate?
  $included_fields = array(
    'text',
    'text_long',
    'text_textfield',
    'text_textarea_with_summary',
  );
  $form['lingotek_instructions'] = array(
    '#markup' => '<div>Which content do you want translated?</div>',
  );
  $form['lingotek_top_spacer'] = array(
    '#markup' => '<div>&nbsp;</div>',
  );
  $form['lingotek_checkboxes_open'] = array(
    '#markup' => '<div id="content-checkboxes" style="border: 0px solid red;">',
  );

  // Arrange the Types nicely.
  foreach ($raw_types as $value) {
    $types[$value->type] = $value->name;
    $form['type_' . $value->type] = array(
      '#type' => 'checkbox',
      '#title' => t('@value_name (<span id="showhidelink_@value_type"><a id="showlink_@value_type" href="@url" class="use-ajax">choose fields</a></span>)', array(
        '@value_name' => $value->name,
        '@value_type' => $value->type,
        '@url' => url('admin/config/lingotek/content-type-choose-fields-ajax/' . $value->type),
      )),
      '#return_value' => $value->type,
      '#default_value' => array_key_exists($value->type, $translate) || $use_defaults === TRUE ? TRUE : FALSE,
      '#prefix' => '<div id="content_type_' . $value->type . '">',
      '#suffix' => '</div>' . '',
      '#ajax' => array(
        'event' => 'click',
        'callback' => 'lingotek_content_type_checkbox_callback',
        'wrapper' => 'content_fields_' . $value->type,
      ),
    );

    // Grab the fields for this Content Type.
    $fields = field_info_instances('node', $value->type);
    $switch = array_key_exists($value->type, $translate) ? 'block' : 'none';
    $form['lingotek_' . $value->type . 'fieldlist_open'] = array(
      '#markup' => '<div id="content_fields_' . $value->type . '" style="display: ' . $switch . ';">',
    );
    $form['lingotek_fieldlist_details_' . $value->type] = array(
      '#markup' => '<div style="padding-left: 25px; padding-bottom: 5px;">Which fields would you like to include:</div>',
    );
    $title_found = FALSE;

    // Is there a title field present?
    // Loop the fields, outputting them.
    foreach ($fields as $field) {
      $field_label = $field['label'];
      $field_machine_name = $field['field_name'];
      $field_type = $field['widget']['type'];
      $field_name = $value->type . '_SEPERATOR_' . $field_machine_name;
      if ($field_label == 'Title' && $field_type == 'text_textfield') {
        $title_found = TRUE;
      }

      /*
      $rand = rand();
      $form['lingotek_fieldlist_debug_'.$rand] = array( '#markup' => '<div>'
        .'Name: ' .$field_name .'<br>'
        .'Label: ' .$field_label .'<br>'
        .'Type: ' .$field_type .'<br>'
        .'</div>' );
      */

      // Exclude field types we dont translate.
      if (TRUE == array_search($field_type, $included_fields)) {
        $form[$field_name] = array(
          '#type' => 'checkbox',
          '#title' => t('@fieldlabel [@fieldtype]', array(
            '@fieldlabel' => $field_label,
            '@fieldtype' => $field_type,
          )),
          // Set if your machine type is set to translate, and your field has been flagged for translation.   OR!  If use defaults == TRUE, and your field type has text in the name somewhere
          '#default_value' => isset($translate[$value->type]) && FALSE !== array_search($field_machine_name, $translate[$value->type]) || $use_defaults === TRUE && strpos($field_type, 'text') !== FALSE ? TRUE : FALSE,
          '#prefix' => '<div style="padding-left: 35px;">',
          '#suffix' => '</div>',
        );
      }
    }

    // END:  foreach field
    // if we did NOT find a title field for the specified content type, add it manually as an option, and we can do a title swap for the user.
    if ($title_found === FALSE) {
      $form['title_swap_' . $value->type] = array(
        '#type' => 'checkbox',
        '#title' => t('Title (Note: Field Will Be Created.)'),
        '#default_value' => TRUE,
        '#prefix' => '<div style="padding-left: 35px;">',
        '#suffix' => '</div>',
      );
    }
    $form['lingotek_' . $value->type . 'fieldlist_close'] = array(
      '#markup' => '</div>',
    );
    $rand = rand();
    $form['lingotek_after_fields_' . $rand] = array(
      '#markup' => '<div>&nbsp;</div>',
    );
  }

  // END:  foreach content type
  $form['lingotek_checkboxes_close'] = array(
    '#markup' => '</div>',
  );
  $form['lingotek_button_spacer'] = array(
    '#markup' => '<div>&nbsp;</div>',
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Next'),
  );
  if (is_array($_SESSION['lingotek_setup_path'])) {
    if (end($_SESSION['lingotek_setup_path']) == 'admin/config/lingotek/node-translation-settings') {
      $null = array_pop($_SESSION['lingotek_setup_path']);
    }

    // if the user went back, remove the last element, which is this page.
    $form['lingotek_back_button'] = lingotek_setup_link(end($_SESSION['lingotek_setup_path']), t('Previous Step'));
  }
  $form['lingotek_support_footer'] = lingotek_support_footer();
  return $form;
}