taxonomy_form_term($form, &$form_state, $edit = array(), $vocabulary = NULL)Form function for the term edit form.
modules/taxonomy/taxonomy.admin.inc, line 607
<?php
function taxonomy_form_term($form, &$form_state, $edit = array(), $vocabulary = NULL) {
if (!isset($vocabulary) && is_object($edit)) {
$vocabulary = taxonomy_vocabulary_load($edit->vid);
$edit = (array)$edit;
}
$edit += array(
'name' => '',
'description' => '',
'format' => filter_default_format(),
'vocabulary_machine_name' => $vocabulary->machine_name,
'tid' => NULL,
'weight' => 0,
);
// Take into account multi-step rebuilding.
if (isset($form_state['term'])) {
$edit = $form_state['term'] + $edit;
}
$parent = array_keys(taxonomy_get_parents($edit['tid']));
$form['#term'] = $edit;
$form['#term']['parent'] = $parent;
$form['#vocabulary'] = $vocabulary;
$form['#builder_function'] = 'taxonomy_form_term_submit_builder';
// Check for confirmation forms.
if (isset($form_state['confirm_delete'])) {
return array_merge($form, taxonomy_term_confirm_delete($form, $form_state, $edit['tid']));
}
elseif (isset($form_state['confirm_parents'])) {
return array_merge($form, taxonomy_term_confirm_parents($form, $form_state, $vocabulary));
}
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
'#default_value' => $edit['name'],
'#maxlength' => 255,
'#required' => TRUE,
'#weight' => -5,
);
$form['description'] = array(
'#type' => 'text_format',
'#title' => t('Description'),
'#default_value' => $edit['description'],
'#format' => $edit['format'],
'#weight' => 0,
);
$form['vocabulary_machine_name'] = array(
'#type' => 'textfield',
'#access' => FALSE,
'#value' => isset($edit['vocabulary_machine_name']) ? $edit['vocabulary_machine_name'] : $vocabulary->name,
);
field_attach_form('taxonomy_term', (object) $edit, $form, $form_state);
$form['relations'] = array(
'#type' => 'fieldset',
'#title' => t('Relations'),
'#collapsible' => TRUE,
'#collapsed' => $vocabulary->hierarchy < 2,
'#weight' => 10,
);
// 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'];
$tree = taxonomy_get_tree($vocabulary->vid);
$options = array('<' . t('root') . '>');
foreach ($tree as $term) {
if (!in_array($term->tid, $exclude)) {
$options[$term->tid] = str_repeat('-', $term->depth) . $term->name;
}
}
$form['relations']['parent'] = array(
'#type' => 'select',
'#title' => t('Parent terms'),
'#options' => $options,
'#default_value' => $parent,
'#multiple' => TRUE,
);
}
$form['relations']['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['tid'] = array(
'#type' => 'value',
'#value' => $edit['tid'],
);
$form['actions'] = array(
'#type' => 'container',
'#attributes' => array('class' => array('form-actions')),
'#weight' => 100,
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#weight' => 5,
);
if ($edit['tid']) {
$form['actions']['delete'] = array(
'#type' => 'submit',
'#value' => t('Delete'),
'#access' => user_access("delete terms in $vocabulary->vid") || user_access('administer taxonomy'),
'#weight' => 10,
);
}
else {
$form_state['redirect'] = $_GET['q'];
}
return $form;
}
?>