taxonomy_form_term
- Versions
- 4.6 – 4.7
taxonomy_form_term($edit = array())- 5
taxonomy_form_term($vocabulary_id, $edit = array())- 6
taxonomy_form_term(&$form_state, $vocabulary, $edit = array())- 7
taxonomy_form_term($form, &$form_state, $edit = array(), $vocabulary = NULL)
Form function for the term edit form.
See also
Related topics
Code
modules/taxonomy/taxonomy.admin.inc, line 608
<?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['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,
'#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.'),
'#text_format' => $edit['format'],
);
$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['advanced'] = array(
'#type' => 'fieldset',
'#title' => t('Advanced options'),
'#collapsible' => TRUE,
'#collapsed' => $vocabulary->hierarchy < 2,
);
// 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['advanced']['parent'] = array(
'#type' => 'select',
'#title' => t('Parent terms'),
'#options' => $options,
'#default_value' => $parent,
'#multiple' => TRUE,
);
}
$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'),
'#access' => user_access("delete terms in $vocabulary->vid") || user_access('administer taxonomy'),
);
$form['tid'] = array(
'#type' => 'value',
'#value' => $edit['tid']);
}
else {
$form_state['redirect'] = $_GET['q'];
}
return $form;
}
?>Login or register to post comments 