You are here

function lingotek_get_language_override_form in Lingotek Translation 7.7

Same name and namespace in other branches
  1. 7.6 lingotek.module \lingotek_get_language_override_form()

Display the Lingotek language-override form field

1 call to lingotek_get_language_override_form()
lingotek_form_node_form_alter in ./lingotek.module
Implements hook_form_BASE_FORM_ID_alter().

File

./lingotek.module, line 823

Code

function lingotek_get_language_override_form($form, &$form_state, $node = NULL) {
  $locales = lingotek_get_target_locales(FALSE);
  $lang_options = array();
  foreach ($locales as $l => $v) {
    $lang_options[$v->language] = $v->name;
  }
  unset($lang_options[$node->language]);
  $form['language_override'] = array(
    '#type' => 'select',
    '#title' => t('Language Override'),
    '#description' => t('Specify the language of the data currently contained in the fields if different from the language set for this node.'),
    '#options' => $lang_options,
    '#empty_option' => t('(none)'),
    '#weight' => 50,
  );
  $source_language = !empty($form_state['values']['language']) ? $form_state['values']['language'] : NULL;
  if (!$source_language) {
    $source_language = !empty($form_state['node']->language) ? $form_state['node']->language : NULL;
  }
  $language_override = !empty($source_language) ? 'source_language_' . Lingotek::convertDrupal2Lingotek($source_language) : NULL;
  if ($language_override && !empty($node->lingotek[$language_override])) {
    $form['language_override']['#default_value'] = $node->lingotek[$language_override];
  }
  $profiles = lingotek_get_profiles();
  foreach ($profiles as $k => $p) {
    $form[$k . '_override'] = array(
      '#type' => 'hidden',
      '#value' => $p
        ->getAttribute('allow_source_overwriting') ? 'true' : 'false',
    );
  }
  $form['actions']['submit']['#submit'][] = 'lingotek_get_language_override_form_submit';
  return $form;
}