You are here

function lingotek_admin_node_translation_settings_form in Lingotek Translation 7.4

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

Content 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 101

Code

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

  //$setup_complete = variable_get('lingotek_setup_complete', 0);
  $setup_complete = !lingotek_is_config_missing();
  $entity_type_info = entity_get_info($entity_type);
  $bundles = $entity_type_info['bundles'];
  $types = array();
  $translate = variable_get('lingotek_enabled_fields', array());
  $translate = isset($translate[$entity_type]) ? $translate[$entity_type] : array();
  $profiles = lingotek_get_profiles();
  $profile_options = array();
  foreach ($profiles as $key => $profile) {
    $profile_options[$key] = $profile['name'];
  }
  $profile_options[LingotekSync::PROFILE_CUSTOM] = 'Custom';
  $profile_options[LingotekSync::PROFILE_DISABLED] = 'Disabled';
  if ($entity_type == 'field_collection_item') {
    $profile_options = array(
      'ENABLED' => 'Enabled',
      LingotekSync::PROFILE_DISABLED => 'Disabled',
    );
    $entity_type_info['label'] = 'Field Collection';
  }
  $entity_profiles = variable_get('lingotek_entity_profiles');

  // What types of fields DO we translate?
  $translatable_field_types = lingotek_get_translatable_field_types();
  $form['entity_type'] = array(
    '#type' => 'hidden',
    '#value' => $entity_type,
  );
  $form['node_translation'] = array(
    '#type' => $show_fieldset ? 'fieldset' : 'item',
    '#title' => $setup_complete ? t('Translate @types', array(
      '@type' => $entity_type_info['label'],
    )) : t('Which content types do you want translated?'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#group' => 'administrative_settings',
    'actions' => array(
      '#type' => 'actions',
    ),
    '#submit' => array(
      'lingotek_admin_node_translation_settings_form_submit',
    ),
  );
  if ($setup_complete) {
    $form['node_translation'][] = array(
      '#type' => 'item',
      '#description' => t('Choose what you want translated:'),
    );
  }
  $rows = array();
  foreach ($bundles as $bundle_name => $bundle) {
    $fr = array();
    foreach (field_info_instances($entity_type, $bundle_name) as $field) {
      $field_label = $field['label'];
      $field_machine_name = $field['field_name'];
      $field_type = $field['widget']['type'];
      if (array_search($field_type, $translatable_field_types)) {
        $fr[$field_machine_name] = array(
          '#type' => 'checkbox',
          '#title' => check_plain($field_label),
          '#attributes' => array(
            'id' => array(
              'edit-form-item-' . $bundle_name . '-seperator-' . $field_machine_name,
            ),
            'name' => $bundle_name . '_SEPERATOR_' . $field_machine_name,
            'class' => array(
              'field',
            ),
          ),
          '#id' => 'edit-form-item-' . $bundle_name . '-seperator-' . $field_machine_name,
          '#states' => array(
            'invisible' => array(
              ':input[name="profile_' . $bundle_name . '"]' => array(
                'value' => 'DISABLED',
              ),
            ),
          ),
        );
        $is_enabled = !empty($translate[$bundle_name]) && array_search($field_machine_name, $translate[$bundle_name]) !== FALSE;
        if (!$setup_complete || $is_enabled) {
          $fr[$field_machine_name]['#attributes']['checked'] = 'checked';
        }
      }
    }
    $missing_title = !isset($fr['title_field']) && $entity_type == 'node';
    $missing_subject = !isset($fr['subject_field']) && $entity_type == 'comment';
    if ($missing_title || $missing_subject) {
      $message = $entity_type == 'node' ? 'Title (Note: field will be created.)' : 'Subject (Note: field will be created.)';
      $fr['title_field'] = array(
        '#type' => 'checkbox',
        '#title' => $message,
        '#attributes' => array(
          'id' => array(
            'edit-form-item-' . $bundle_name . '-seperator-title',
          ),
          'name' => 'title_swap_' . $bundle_name,
          'class' => array(
            'field',
          ),
        ),
        '#id' => 'edit-form-item-' . $bundle_name . '-seperator-title',
        '#states' => array(
          'invisible' => array(
            ':input[name="profile_' . $bundle_name . '"]' => array(
              'value' => 'DISABLED',
            ),
          ),
        ),
      );
      if (!$setup_complete) {
        $fr['title_field']['#attributes']['checked'] = 'checked';
      }
    }
    $default_profile = $setup_complete ? LingotekSync::PROFILE_DISABLED : 0;
    $fr2 = array();
    $fr2['profile_' . $bundle_name] = array(
      '#type' => 'select',
      '#options' => $profile_options,
      '#value' => isset($entity_profiles[$entity_type][$bundle_name]) ? $entity_profiles[$entity_type][$bundle_name] : $default_profile,
      '#attributes' => array(
        'id' => array(
          'edit-form-item-profile-' . $bundle_name,
        ),
        'name' => 'profile_' . $bundle_name,
        'class' => array(
          'field',
        ),
      ),
    );
    $rows[$bundle_name] = array(
      array(
        'data' => $bundle['label'],
        'width' => '20%',
      ),
      array(
        'data' => drupal_render($fr2),
      ),
      array(
        'data' => drupal_render($fr),
        'width' => '65%',
      ),
    );
  }
  $header = array(
    t('Content Type'),
    t('Translation Profile *'),
    t('Fields'),
  );
  if ($entity_type == 'field_collection_item') {
    $header = array(
      t('Collection Name'),
      t('Status *'),
      t('Fields'),
    );
  }
  $variables = array(
    'header' => $header,
    'rows' => $rows,
    'attributes' => array(
      'class' => array(
        'lingotek-content-settings-table',
      ),
    ),
  );
  $form['node_translation']['types'] = array(
    '#type' => 'markup',
    '#markup' => theme('table', $variables),
    '#suffix' => '* Note: changing the profile will update existing nodes for all settings except the project, workflow, vault, and method (e.g. node/field)',
  );
  if ($entity_type == 'field_collection_item') {
    $form['node_translation']['types']['#suffix'] = '* Note: Field collections will be uploaded and downloaded at the same time as their parent.';
  }
  $form['node_translation']['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}