taxonomy_form_term

5 taxonomy.module taxonomy_form_term($vocabulary_id, $edit = array())
6 taxonomy.admin.inc taxonomy_form_term(&$form_state, $vocabulary, $edit = array())
7 taxonomy.admin.inc taxonomy_form_term($form, &$form_state, $edit = array(), $vocabulary = NULL)
8 taxonomy.admin.inc taxonomy_form_term($form, &$form_state, TaxonomyTerm $term = NULL, TaxonomyVocabulary $vocabulary = NULL)

2 string references to 'taxonomy_form_term'

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;
}
Login or register to post comments