1 taxonomy.admin.inc | taxonomy_form_vocabulary($form, &$form_state, TaxonomyVocabulary $vocabulary = NULL) |
Form builder for the vocabulary editing form.
See also
taxonomy_form_vocabulary_submit()
taxonomy_form_vocabulary_validate()
Related topics
File
- core/
modules/ taxonomy/ taxonomy.admin.inc, line 144 - Admin page callbacks for the Taxonomy module.
Code
function taxonomy_form_vocabulary($form, &$form_state, TaxonomyVocabulary $vocabulary = NULL) {
// During initial form build, add the entity to the form state for use
// during form building and processing. During a rebuild, use what is in the
// form state.
if (!isset($form_state['vocabulary'])) {
// Create a new TaxonomyVocabulary entity for the add form.
if (!isset($vocabulary)) {
backdrop_set_title(t('Add vocabulary'));
$vocabulary = new TaxonomyVocabulary();
}
$form_state['vocabulary'] = $vocabulary;
}
else {
$vocabulary = $form_state['vocabulary'];
}
$form['#vocabulary'] = $form_state['vocabulary'];
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
'#default_value' => $vocabulary->name,
'#maxlength' => 255,
'#required' => TRUE,
);
$form['machine_name'] = array(
'#type' => 'machine_name',
'#default_value' => $vocabulary->machine_name,
'#maxlength' => 255,
'#disabled' => !empty($vocabulary->machine_name),
'#machine_name' => array(
'exists' => 'taxonomy_vocabulary_load',
),
);
$form['description'] = array(
'#type' => 'textfield',
'#title' => t('Description'),
'#default_value' => $vocabulary->description,
);
// Set the hierarchy to "multiple parents" by default. This simplifies the
// vocabulary form and standardizes the term form.
$form['hierarchy'] = array(
'#type' => 'value',
'#value' => '0',
);
$form['additional_settings'] = array(
'#type' => 'vertical_tabs',
'#attached' => array(
'js' => array(backdrop_get_path('module', 'taxonomy') . '/js/taxonomy.vocabulary.js'),
),
'#weight' => 99,
);
// Vocabulary permissions.
$form['permissions'] = array(
'#type' => 'fieldset',
'#title' => t('Permissions'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#group' => 'additional_settings',
'#access' => user_access('administer permissions'),
);
$form['permissions']['permissions'] = taxonomy_vocabulary_form_permissions($vocabulary);
if (module_exists('language')) {
$form['multilingual'] = array(
'#type' => 'fieldset',
'#title' => t('Multilingual support'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#group' => 'additional_settings',
);
$form['multilingual']['language'] = array(
'#type' => 'checkbox',
'#title' => t('Multilingual support'),
'#default_value' => $vocabulary->language,
'#description' => t('Add a language selection field to the editing form, allowing you to select from one of the <a href="!languages">enabled languages</a>. If disabled, new terms are saved with no defined language. Existing terms will not be affected by changing this option.', array('!languages' => url('admin/config/regional/language'))),
);
}
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save vocabulary'),
'#weight' => 2,
);
// Only show 'Save and add terms' button when creating new vocabulary.
if ($vocabulary->machine_name == NULL) {
$form['actions']['continue'] = array(
'#type' => 'submit',
'#value' => t('Save and add terms'),
'#weight' => 1,
);
}
$form['actions']['cancel'] = array(
'#type' => 'link',
'#title' => t('Cancel'),
'#href' => 'admin/structure/taxonomy',
'#options' => array('attributes' => array('class' => array('form-cancel'))),
'#weight' => 15,
);
return $form;
}