function taxonomy_defaults_form in Taxonomy Defaults 6
Same name and namespace in other branches
- 5 taxonomy_defaults.module \taxonomy_defaults_form()
- 6.2 taxonomy_defaults.admin.inc \taxonomy_defaults_form()
- 7 taxonomy_defaults.admin.inc \taxonomy_defaults_form()
Defines the page at admin/content/taxonomy/taxonomy_defaults.
1 string reference to 'taxonomy_defaults_form'
- taxonomy_defaults_menu in ./
taxonomy_defaults.module - Define a custom callback to assign default terms menu at a tab on admin/taxonomy.
File
- ./
taxonomy_defaults.admin.inc, line 11 - Administration forms for the taxonomy_defaults module
Code
function taxonomy_defaults_form() {
// For each node type we generate per vocabulary a checkbox & term select.
$form['#tree'] = TRUE;
$vocabularies = taxonomy_get_vocabularies();
foreach (node_get_types() as $type => $name) {
$type_vocabularies = taxonomy_get_vocabularies($type);
// Loop over all vocabularies
foreach ($vocabularies as $vid => $vocab) {
$activevocab = array_key_exists($vid, $type_vocabularies);
if ($activevocab) {
$form[$type][$vid]['hide_vocab'] = array(
'#type' => 'checkbox',
'#default_value' => !variable_get("taxdef_{$type}_{$vid}_visible", TRUE),
'#weight' => -16,
);
$form[$type][$vid]['name'] = array(
'#value' => t($vocab->name),
);
// If the vocabulary stores tags, add an autocomplete field for it.
if ($vocab->tags) {
$stored_terms = variable_get("taxdef_{$type}_{$vid}", array());
$stored_tags = array();
foreach ($stored_terms as $tid) {
$term = taxonomy_get_term($tid);
if ($term) {
$stored_tags[] = $term->name;
}
}
$stored_tags = drupal_implode_tags($stored_tags);
$form[$type][$vid]['tags'] = array(
'#type' => 'textfield',
'#description' => "Begin typing",
'#default_value' => $stored_tags,
'#autocomplete_path' => 'taxonomy/autocomplete/' . $vocab->vid,
'#maxlength' => 255,
);
}
else {
$form[$type][$vid]['select'] = taxonomy_form($vid, variable_get("taxdef_{$type}_{$vid}", 0));
}
}
else {
if (variable_get("taxdef_{$type}_{$vid}", FALSE)) {
drupal_set_message(t("Taxonomy Defaults were detected for the @vocab vocabulary on the @type content type, but @type is not selected in @vocab !settings. !details.", array(
'@vocab' => $vocab->name,
'@type' => $type,
'!settings' => l('settings', '/admin/content/taxonomy/edit/vocabulary/' . $vid),
'!details' => l('Explanation', 'http://drupal.org/node/559828#comment-2162950'),
)), "warning");
}
}
}
}
if (count($vocabularies) > 0) {
$form['buttons']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save configuration'),
);
$form['buttons']['reset'] = array(
'#type' => 'submit',
'#value' => t('Reset to defaults'),
'#submit' => array(
'taxonomy_defaults_reset_submit',
),
);
}
else {
$form['text'] = array(
'#value' => t('Before you can assign default terms to node types, go to !link to create and fill vocabularies.', array(
'!link' => l(t('add vocabulary'), 'admin/content/taxonomy/add/vocabulary'),
)),
);
}
return $form;
}