You are here

function taxonomy_manager_double_tree_add_translation_validate in Taxonomy Manager 7

Validation handler for adding a translation.

1 string reference to 'taxonomy_manager_double_tree_add_translation_validate'
taxonomy_manager_double_tree_form in ./taxonomy_manager.admin.inc

File

./taxonomy_manager.admin.inc, line 2273

Code

function taxonomy_manager_double_tree_add_translation_validate($form, &$form_state) {
  if (!module_exists('i18n_taxonomy')) {
    form_set_error('', t("i18n taxonomy module is not enabled."));
    return;
  }
  if (!count($form_state['values']['taxonomy']['manager']['tree']['selected_terms']) || !count($form_state['values']['taxonomy2']['manager']['tree']['selected_terms'])) {
    form_set_error('', t("No terms selected."));
    return;
  }
  $term1 = taxonomy_term_load(array_shift($form_state['values']['taxonomy']['manager']['tree']['selected_terms']));
  $term2 = taxonomy_term_load(array_shift($form_state['values']['taxonomy2']['manager']['tree']['selected_terms']));
  $voc = $form_state['values']['voc'];
  if (!i18n_taxonomy_vocabulary_mode($voc->vid, I18N_MODE_TRANSLATE)) {
    form_set_error('', t('This is not a multilingual vocabulary.'));
    return;
  }
  elseif ($term1->language == $term2->language) {
    form_set_error('', t("Selected terms are of the same language."));
    return;
  }
  elseif (!is_null(i18n_taxonomy_term_get_translation($term1, $term2->language)) || !is_null(i18n_taxonomy_term_get_translation($term2, $term1->language))) {
    form_set_error('', t('A translation for this term or language already exists.'));
    return;
  }

  // Set the values for the submit handler.
  $values = array(
    'term1' => $term1,
    'term2' => $term2,
    'voc' => $voc,
  );
  form_set_value(array(
    '#parents' => array(
      'double_tree_values',
    ),
  ), $values, $form_state);
}