You are here

function taxonomy_form_term in Drupal 6

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

Form function for the term edit form.

See also

taxonomy_form_term_submit()

Related topics

3 string references to 'taxonomy_form_term'
forum_form_alter in modules/forum/forum.module
Implementation of hook_form_alter().
taxonomy_add_term_page in modules/taxonomy/taxonomy.admin.inc
Menu callback; return the edit form for a new term after setting the title.
taxonomy_admin_term_edit in modules/taxonomy/taxonomy.admin.inc
Page to edit a vocabulary term.

File

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

Code

function taxonomy_form_term(&$form_state, $vocabulary, $edit = array()) {
  $edit += array(
    'name' => '',
    'description' => '',
    'tid' => NULL,
    'weight' => 0,
  );
  $parent = array_keys(taxonomy_get_parents($edit['tid']));
  $form['#term'] = $edit;
  $form['#term']['parent'] = $parent;
  $form['#vocabulary'] = (array) $vocabulary;
  $form['#vocabulary']['nodes'] = drupal_map_assoc($vocabulary->nodes);

  // Check for confirmation forms.
  if (isset($form_state['confirm_delete'])) {
    return array_merge($form, taxonomy_term_confirm_delete($form_state, $edit['tid']));
  }
  elseif (isset($form_state['confirm_parents'])) {
    return array_merge($form, taxonomy_term_confirm_parents($form_state, $vocabulary));
  }
  $form['identification'] = array(
    '#type' => 'fieldset',
    '#title' => t('Identification'),
    '#collapsible' => TRUE,
  );
  $form['identification']['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Term name'),
    '#default_value' => $edit['name'],
    '#maxlength' => 255,
    '#description' => t('The name of this term.'),
    '#required' => TRUE,
  );
  $form['identification']['description'] = array(
    '#type' => 'textarea',
    '#title' => t('Description'),
    '#default_value' => $edit['description'],
    '#description' => t('A description of the term. To be displayed on taxonomy/term pages and RSS feeds.'),
  );
  $form['advanced'] = array(
    '#type' => 'fieldset',
    '#title' => t('Advanced options'),
    '#collapsible' => TRUE,
    '#collapsed' => $vocabulary->hierarchy > 1 ? FALSE : TRUE,
  );

  // taxonomy_get_tree and taxonomy_get_parents may contain large numbers of
  // items so we check for taxonomy_override_selector before loading the
  // full vocabulary. Contrib modules can then intercept before
  // hook_form_alter to provide scalable alternatives.
  if (!variable_get('taxonomy_override_selector', FALSE)) {
    $parent = array_keys(taxonomy_get_parents($edit['tid']));
    $children = taxonomy_get_tree($vocabulary->vid, $edit['tid']);

    // A term can't be the child of itself, nor of its children.
    foreach ($children as $child) {
      $exclude[] = $child->tid;
    }
    $exclude[] = $edit['tid'];
    $form['advanced']['parent'] = _taxonomy_term_select(t('Parents'), 'parent', $parent, $vocabulary->vid, t('Parent terms') . '.', 1, '<' . t('root') . '>', $exclude);
    $form['advanced']['relations'] = _taxonomy_term_select(t('Related terms'), 'relations', array_keys(taxonomy_get_related($edit['tid'])), $vocabulary->vid, NULL, 1, '<' . t('none') . '>', array(
      $edit['tid'],
    ));
  }
  $form['advanced']['synonyms'] = array(
    '#type' => 'textarea',
    '#title' => t('Synonyms'),
    '#default_value' => implode("\n", taxonomy_get_synonyms($edit['tid'])),
    '#description' => t('Synonyms of this term, one synonym per line.'),
  );
  $form['advanced']['weight'] = array(
    '#type' => 'textfield',
    '#title' => t('Weight'),
    '#size' => 6,
    '#default_value' => $edit['weight'],
    '#description' => t('Terms are displayed in ascending order by weight.'),
    '#required' => TRUE,
  );
  $form['vid'] = array(
    '#type' => 'value',
    '#value' => $vocabulary->vid,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  if ($edit['tid']) {
    $form['delete'] = array(
      '#type' => 'submit',
      '#value' => t('Delete'),
    );
    $form['tid'] = array(
      '#type' => 'value',
      '#value' => $edit['tid'],
    );
  }
  else {
    $form['destination'] = array(
      '#type' => 'hidden',
      '#value' => $_GET['q'],
    );
  }
  return $form;
}