You are here

function taxonomy_manager_double_tree_copy_submit in Taxonomy Manager 7

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

File

./taxonomy_manager.admin.inc, line 2195

Code

function taxonomy_manager_double_tree_copy_submit($form, &$form_state) {
  $selected_terms = $form_state['values']['double_tree_values']['selected_terms'];
  $selected_parents = $form_state['values']['double_tree_values']['selected_parents'];
  $voc1 = $form_state['values']['double_tree_values']['voc1'];
  $voc2 = $form_state['values']['double_tree_values']['voc2'];
  $voc1 = taxonomy_vocabulary_load($voc1);
  $voc2 = taxonomy_vocabulary_load($voc2);
  $new_tids = taxonomy_manager_copy($selected_terms, $voc1->vid, $voc2->vid, $selected_parents);
  if (count($new_tids)) {
    $new_tid = array_pop($new_tids);
    $form_state['values']['double_tree_values']['left_tree_expand_terms'] = array(
      $new_tid,
    );
    $form_state['values']['double_tree_values']['right_tree_expand_terms'] = array(
      $new_tid,
    );
  }
  $selected_terms_names = array();
  foreach ($selected_terms as $tid) {
    $term = taxonomy_term_load($tid);
    $selected_terms_names[] = $term->name;
  }
  $selected_parent_names = array();
  if (count($selected_parents)) {
    foreach ($selected_parents as $parent) {
      $term = taxonomy_term_load($parent);
      $selected_parent_names[] = $term->name;
      $term_parents_array[$term->tid] = $term->tid;
    }
  }
  $term_names = implode(', ', $selected_terms_names);
  if (count($selected_parents) == 0) {
    drupal_set_message(t("Copied %terms to vocabulary %voc.", array(
      '%terms' => $term_names,
      '%voc' => $voc2->name,
    )));
  }
  else {
    drupal_set_message(t("Copied %terms to vocabulary %voc under parents %parents.", array(
      '%terms' => $term_names,
      '%voc' => $voc2->name,
      '%parents' => implode(', ', $selected_parent_names),
    )));
  }
  $form_state['rebuild'] = TRUE;
}