taxonomy_form_term
modules/taxonomy/taxonomy.admin.inc, строка 633
- Версии
- 5
taxonomy_form_term(
$vocabulary_id, $edit = array())- 6
taxonomy_form_term(&$form_state, $vocabulary, $edit = array())
Связанные темы
Код
<?php
function taxonomy_form_term(&$form_state, $vocabulary, $edit = array()) {
$edit += array(
'name' => '',
'description' => '',
'tid' => NULL,
'weight' => 0,
);
$parent = array_keys(taxonomy_get_parents($edit['tid']));
$form['#term'] = $edit;
$form['#term']['parent'] = $parent;
$form['#vocabulary'] = (array)$vocabulary;
$form['#vocabulary']['nodes'] = drupal_map_assoc($vocabulary->nodes);;
// Check for confirmation forms.
if (isset($form_state['confirm_delete'])) {
return array_merge($form, taxonomy_term_confirm_delete($form_state, $edit['tid']));
}
elseif (isset($form_state['confirm_parents'])) {
return array_merge($form, taxonomy_term_confirm_parents($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,
'#description' => t('The name of this term.'),
'#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.'));
$form['advanced'] = array(
'#type' => 'fieldset',
'#title' => t('Advanced options'),
'#collapsible' => TRUE,
'#collapsed' => $vocabulary->hierarchy > 1 ? FALSE : TRUE,
);
// 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'];
$form['advanced']['parent'] = _taxonomy_term_select(t('Parents'), 'parent', $parent, $vocabulary->vid, t('Parent terms') .'.', 1, '<'. t('root') .'>', $exclude);
$form['advanced']['relations'] = _taxonomy_term_select(t('Related terms'), 'relations', array_keys(taxonomy_get_related($edit['tid'])), $vocabulary->vid, NULL, 1, '<'. t('none') .'>', array($edit['tid']));
}
$form['advanced']['synonyms'] = array(
'#type' => 'textarea',
'#title' => t('Synonyms'),
'#default_value' => implode("\n", taxonomy_get_synonyms($edit['tid'])),
'#description' => t('Synonyms of this term, one synonym per line.'));
$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'));
$form['tid'] = array(
'#type' => 'value',
'#value' => $edit['tid']);
}
else {
$form['destination'] = array('#type' => 'hidden', '#value' => $_GET['q']);
}
return $form;
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии