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

File

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

Code

function taxonomy_form_term($edit = array()) {
  $vocabulary_id = isset($edit['vid']) ? $edit['vid'] : arg(4);
  $vocabulary = taxonomy_get_vocabulary($vocabulary_id);
  $form = form_textfield(t('Term name'), 'name', $edit['name'], 50, 64, t('The name for this term.  Example: "Linux".'), NULL, TRUE);
  $form .= form_textarea(t('Description'), 'description', $edit['description'], 60, 5, 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 .= _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 .= _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 .= _taxonomy_term_select(t('Related terms'), 'relations', array_keys(taxonomy_get_related($edit['tid'])), $vocabulary_id, NULL, 1, '<' . t('none') . '>', array(
      $edit['tid'],
    ));
  }
  $form .= form_textarea(t('Synonyms'), 'synonyms', implode("\n", taxonomy_get_synonyms($edit['tid'])), 30, 5, 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 .= form_weight(t('Weight'), 'weight', $edit['weight'], 10, t('In listings, the heavier terms will sink and the lighter terms will be positioned nearer the top.'));
  $form .= form_hidden('vid', $vocabulary->vid);
  $form .= form_submit(t('Submit'));
  if ($edit['tid']) {
    $form .= form_submit(t('Delete'));
    $form .= form_hidden('tid', $edit['tid']);
  }
  else {
    $form .= form_hidden('destination', $_GET['q']);
  }
  return form($form);
}