You are here

function taxonomy_manager_form_submit in Taxonomy Manager 5

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

submits the taxonomy manager form

File

./taxonomy_manager.module, line 928
Taxonomy Manager

Code

function taxonomy_manager_form_submit($form_id, $form_values) {
  $selected_tids = array();
  $selected_tids = $form_values['taxonomy']['manager']['tree']['selected_terms'];
  switch ($form_values['op']) {
    case t('Search'):
      $search_string = $form_values['search']['field'];
      $terms = array();
      $terms = taxonomy_manager_autocomplete_tags_get_tids($search_string, $form_values['vid'], FALSE);
      $term = array_shift($terms);
      $tid = $term['tid'];
      if ($tid) {
        drupal_goto('admin/content/taxonomy_manager/' . $form_values['vid'] . '/' . $tid);
      }
      else {
        drupal_goto('admin/content/taxonomy_manager/' . $form_values['vid'] . '/0/' . $search_string);
      }
      break;
    case t('Add'):
      $terms = array();
      foreach ($form_values['add']['term'] as $value) {
        if (!empty($value)) {
          $terms[] = $value;
        }
      }
      if ($form_values['add']['mass']['mass_add']) {
        foreach (explode("\n", str_replace("\r", '', $form_values['add']['mass']['mass_add'])) as $term) {
          if ($term) {
            $terms[] = $term;
          }
        }
      }
      foreach ($terms as $name) {
        $term = array();
        $term['name'] = $name;
        $term['vid'] = $form_values['vid'];
        $term['parent'] = $selected_tids;
        taxonomy_save_term($term);
      }
      drupal_set_message("Terms added: " . implode(', ', $terms));
      break;
    case t('Merge'):
      $main_terms = taxonomy_manager_autocomplete_tags_get_tids($form_values['merge']['main_term'], $form_values['vid']);
      $main_term = array_shift($main_terms);
      $new_inserted = false;
      if ($main_term['new']) {
        $new_inserted = true;
      }
      $main_term_tid = $main_term['tid'];
      taxonomy_manager_merge($main_term_tid, $selected_tids, $form_values['merge']['options'], $new_inserted);
      drupal_set_message("Terms merged");
      break;
    case t('Move'):
      $typed_parents = taxonomy_manager_autocomplete_tags_get_tids($form_values['move']['parents'], $form_values['vid']);
      $parents = array();
      foreach ($typed_parents as $parent_info) {
        $parents[] = $parent_info['tid'];
      }
      if (count($parents) == 0) {
        $parents[0] = 0;
      }

      //if empty, delete all parents
      taxonomy_manager_move($parents, $selected_tids, $form_values['move']['options']);
      drupal_set_message("Terms moved");
      break;
    case t('Export now'):
      drupal_set_message('Needs JavaScript enabled');
      break;
  }
  drupal_goto('admin/content/taxonomy_manager/' . $form_values['vid']);
}