You are here

function lingotek_admin_node_translation_settings_form in Lingotek Translation 7.3

Same name and namespace in other branches
  1. 7.4 lingotek.admin.inc \lingotek_admin_node_translation_settings_form()

Entity translation form

1 call to lingotek_admin_node_translation_settings_form()
lingotek_setup_node_translation_settings_form in ./lingotek.setup.inc
Entity Translation Settings - Form Layout Select the Content Types and Fields to be Translated.
1 string reference to 'lingotek_admin_node_translation_settings_form'
lingotek_admin_configuration_view in ./lingotek.admin.inc

File

./lingotek.admin.inc, line 94

Code

function lingotek_admin_node_translation_settings_form($form, &$form_state, $show_fieldset = FALSE) {

  //$setup_complete = variable_get('lingotek_setup_complete', 0);
  $setup_complete = lingotek_setup_check_credentials();
  $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',
  );
  if (module_exists('link')) {
    $included_fields[] = 'link_field';
  }
  $form['node_translation'] = array(
    '#type' => $show_fieldset ? 'fieldset' : 'item',
    '#title' => $setup_complete ? t('Entity Translation') : t('Which Entity types do you want translated?'),
    '#description' => $setup_complete ? t('Choose the Entity types to be translated:') : '',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#group' => 'administrative_settings',
    'actions' => array(
      '#type' => 'actions',
      'submit' => array(
        '#type' => 'submit',
        '#value' => $setup_complete ? t('Save') : t('Next'),
      ),
    ),
    '#submit' => array(
      'lingotek_admin_node_translation_settings_form_submit',
    ),
  );
  $form['node_translation']['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['node_translation']['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';
    $switch = 'none';
    $form['node_translation']['lingotek_' . $value->type . 'fieldlist_open'] = array(
      '#markup' => '<div id="content_fields_' . $value->type . '" style="display: ' . $switch . ';">',
    );
    $form['node_translation']['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;
      }

      // Exclude field types we dont translate.
      if (TRUE == array_search($field_type, $included_fields)) {
        $form['node_translation'][$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['node_translation']['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['node_translation']['lingotek_' . $value->type . 'fieldlist_close'] = array(
      '#markup' => '</div>',
    );
  }

  // END:  foreach content type
  $form['node_translation']['lingotek_checkboxes_close'] = array(
    '#markup' => '</div>',
  );
  return $form;
}