You are here

function taxonomy_manager_form_add_submit in Taxonomy Manager 6.2

Same name and namespace in other branches
  1. 6 taxonomy_manager.admin.inc \taxonomy_manager_form_add_submit()
  2. 7 taxonomy_manager.admin.inc \taxonomy_manager_form_add_submit()

Submit handler for adding terms

1 string reference to 'taxonomy_manager_form_add_submit'
taxonomy_manager_add_form in ./taxonomy_manager.admin.inc
form for adding terms

File

./taxonomy_manager.admin.inc, line 1170
Taxonomy Manager Admin

Code

function taxonomy_manager_form_add_submit($form, &$form_state) {
  $terms = array();
  $selected_tids = array();
  $selected_tids = $form_state['values']['taxonomy']['manager']['tree']['selected_terms'];
  foreach ($form_state['values']['add']['term'] as $value) {
    if (!empty($value)) {
      $terms[] = $value;
    }
  }
  if ($form_state['values']['add']['mass']['mass_add']) {
    foreach (explode("\n", str_replace("\r", '', $form_state['values']['add']['mass']['mass_add'])) as $term) {
      if ($term) {
        $terms[] = $term;
      }
    }
  }
  foreach ($terms as $name) {
    $term = array();
    $term['name'] = $name;
    $term['vid'] = $form_state['values']['vid'];
    $term['parent'] = $selected_tids;
    taxonomy_save_term($term);
    if (module_exists('i18ntaxonomy')) {
      if (i18ntaxonomy_vocabulary($form_state['values']['vid']) == I18N_TAXONOMY_TRANSLATE && $form_state['values']['taxonomy']['manager']['top']['language'] != "") {
        _i18ntaxonomy_term_set_lang($term['tid'], $form_state['values']['taxonomy']['manager']['top']['language']);
        $updated_lang = TRUE;
      }
    }
  }
  taxonomy_manager_update_voc($form_state['values']['vid'], $selected_tids);
  if (isset($updated_lang) && $updated_lang == TRUE) {
    drupal_set_message(t("Saving terms to language @lang", array(
      '@lang' => locale_language_name($form_state['values']['taxonomy']['manager']['top']['language']),
    )));
  }
  drupal_set_message(t("Terms added: %terms", array(
    '%terms' => implode(', ', $terms),
  )));
}