You are here

function taxonomy_form_term_submit in Drupal 6

Same name and namespace in other branches
  1. 4 modules/taxonomy.module \taxonomy_form_term_submit()
  2. 5 modules/taxonomy/taxonomy.module \taxonomy_form_term_submit()
  3. 7 modules/taxonomy/taxonomy.admin.inc \taxonomy_form_term_submit()

Submit handler to insert or update a term.

See also

taxonomy_form_term()

File

modules/taxonomy/taxonomy.admin.inc, line 747
Administrative page callbacks for the taxonomy module.

Code

function taxonomy_form_term_submit($form, &$form_state) {
  if ($form_state['clicked_button']['#value'] == t('Delete')) {

    // Execute the term deletion.
    if ($form_state['values']['delete'] === TRUE) {
      return taxonomy_term_confirm_delete_submit($form, $form_state);
    }

    // Rebuild the form to confirm term deletion.
    $form_state['rebuild'] = TRUE;
    $form_state['confirm_delete'] = TRUE;
    return;
  }
  elseif ($form_state['clicked_button']['#value'] == t('Save') && !$form['#vocabulary']['tags'] && count($form_state['values']['parent']) > 1 && $form['#vocabulary']['hierarchy'] < 2) {
    $form_state['rebuild'] = TRUE;
    $form_state['confirm_parents'] = TRUE;
    return;
  }
  switch (taxonomy_save_term($form_state['values'])) {
    case SAVED_NEW:
      drupal_set_message(t('Created new term %term.', array(
        '%term' => $form_state['values']['name'],
      )));
      watchdog('taxonomy', 'Created new term %term.', array(
        '%term' => $form_state['values']['name'],
      ), WATCHDOG_NOTICE, l(t('edit'), 'admin/content/taxonomy/edit/term/' . $form_state['values']['tid']));
      break;
    case SAVED_UPDATED:
      drupal_set_message(t('Updated term %term.', array(
        '%term' => $form_state['values']['name'],
      )));
      watchdog('taxonomy', 'Updated term %term.', array(
        '%term' => $form_state['values']['name'],
      ), WATCHDOG_NOTICE, l(t('edit'), 'admin/content/taxonomy/edit/term/' . $form_state['values']['tid']));
      break;
  }
  if (!$form['#vocabulary']['tags']) {
    $current_parent_count = count($form_state['values']['parent']);
    $previous_parent_count = count($form['#term']['parent']);

    // Root doesn't count if it's the only parent.
    if ($current_parent_count == 1 && isset($form_state['values']['parent'][''])) {
      $current_parent_count = 0;
      $form_state['values']['parent'] = array();
    }

    // If the number of parents has been reduced to one or none, do a check on the
    // parents of every term in the vocabulary value.
    if ($current_parent_count < $previous_parent_count && $current_parent_count < 2) {
      taxonomy_check_vocabulary_hierarchy($form['#vocabulary'], $form_state['values']);
    }
    elseif ($current_parent_count > $previous_parent_count && $form['#vocabulary']['hierarchy'] < 2) {
      $form['#vocabulary']['hierarchy'] = $current_parent_count == 1 ? 1 : 2;
      taxonomy_save_vocabulary($form['#vocabulary']);
    }
  }
  $form_state['tid'] = $form_state['values']['tid'];
  $form_state['redirect'] = 'admin/content/taxonomy';
  return;
}