You are here

function taxonomy_form_term in Drupal 5

Same name and namespace in other branches
  1. 4 modules/taxonomy.module \taxonomy_form_term()
  2. 6 modules/taxonomy/taxonomy.admin.inc \taxonomy_form_term()
  3. 7 modules/taxonomy/taxonomy.admin.inc \taxonomy_form_term()
2 string references to 'taxonomy_form_term'
taxonomy_admin_term_edit in modules/taxonomy/taxonomy.module
Page to edit a vocabulary term.
taxonomy_menu in modules/taxonomy/taxonomy.module
Implementation of hook_menu().

File

modules/taxonomy/taxonomy.module, line 393
Enables the organization of content into categories.

Code

function taxonomy_form_term($vocabulary_id, $edit = array()) {
  $vocabulary = taxonomy_get_vocabulary($vocabulary_id);
  drupal_set_title(check_plain($vocabulary->name));
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Term name'),
    '#default_value' => $edit['name'],
    '#maxlength' => 255,
    '#description' => t('The name of this term.'),
    '#required' => TRUE,
  );
  $form['description'] = array(
    '#type' => 'textarea',
    '#title' => t('Description'),
    '#default_value' => $edit['description'],
    '#description' => t('A description of the term.'),
  );
  if ($vocabulary->hierarchy) {
    $parent = array_keys(taxonomy_get_parents($edit['tid']));
    $children = taxonomy_get_tree($vocabulary_id, $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'];
    if ($vocabulary->hierarchy == 1) {
      $form['parent'] = _taxonomy_term_select(t('Parent'), 'parent', $parent, $vocabulary_id, l(t('Parent term'), 'admin/help/taxonomy', NULL, NULL, 'parent') . '.', 0, '<' . t('root') . '>', $exclude);
    }
    elseif ($vocabulary->hierarchy == 2) {
      $form['parent'] = _taxonomy_term_select(t('Parents'), 'parent', $parent, $vocabulary_id, l(t('Parent terms'), 'admin/help/taxonomy', NULL, NULL, 'parent') . '.', 1, '<' . t('root') . '>', $exclude);
    }
  }
  if ($vocabulary->relations) {
    $form['relations'] = _taxonomy_term_select(t('Related terms'), 'relations', array_keys(taxonomy_get_related($edit['tid'])), $vocabulary_id, NULL, 1, '<' . t('none') . '>', array(
      $edit['tid'],
    ));
  }
  $form['synonyms'] = array(
    '#type' => 'textarea',
    '#title' => t('Synonyms'),
    '#default_value' => implode("\n", taxonomy_get_synonyms($edit['tid'])),
    '#description' => t('<a href="@help-url">Synonyms</a> of this term, one synonym per line.', array(
      '@help-url' => url('admin/help/taxonomy', NULL, NULL, 'synonyms'),
    )),
  );
  $form['weight'] = array(
    '#type' => 'weight',
    '#title' => t('Weight'),
    '#default_value' => $edit['weight'],
    '#description' => t('In listings, the heavier terms will sink and the lighter terms will be positioned nearer the top.'),
  );
  $form['vid'] = array(
    '#type' => 'value',
    '#value' => $vocabulary->vid,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
  );
  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;
}