function taxonomy_defaults_form in Taxonomy Defaults 7
Same name and namespace in other branches
- 5 taxonomy_defaults.module \taxonomy_defaults_form()
- 6.2 taxonomy_defaults.admin.inc \taxonomy_defaults_form()
- 6 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($form, &$form_state) {
// For each node type we generate per vocabulary a checkbox & term select.
$form['#tree'] = TRUE;
$vocabularies = taxonomy_get_vocabularies();
// Retrieve the core forum vocabulary id so it can be skipped later
$forum_vid = variable_get('forum_nav_vocabulary', '');
$ignored_settings = array();
foreach (node_type_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]['name'] = array(
'#value' => t($vocab->name),
);
// Ignore the core forum vocabury
if ($forum_vid == $vid) {
$form[$type][$vid]['msg'] = array(
'#value' => t('Defaults cannot be assigned to the Forum vocabulary from Drupal Core.'),
);
continue;
}
$form[$type][$vid]['hide_vocab'] = array(
'#type' => 'checkbox',
'#default_value' => !variable_get("taxdef_{$type}_{$vid}_visible", TRUE),
'#weight' => -16,
);
// 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_term_load($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)) {
$ignored_settings[] = $name->name;
$form[$type][$vid]['name'] = array(
'#value' => t($vocab->name),
);
$form[$type][$vid]['msg'] = array(
'#value' => t("Defaults exist, but are ignored because the @vocab vocabulary is not assigned to the @type content type in the !settings. ", array(
'@vocab' => $vocab->name,
'@type' => $name->name,
'!settings' => l(t('vocabulary settings'), 'admin/structure/taxonomy/edit/vocabulary/' . $vid),
)),
);
}
}
}
}
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/structure/taxonomy/add/vocabulary'),
)),
);
}
if (count($ignored_settings) > 0) {
$ignored_settings = implode(', ', $ignored_settings);
drupal_set_message(t("Some default terms are being ignored because their vocabularies are not assigned to the corresponding content type. If you are upgrading from 6.x-1.0 or earlier to 6.x-1.1 or later, you'll need to update your hidden vocabularies by assigning them to the content types. Expand the content types below for more details. Content types that may be affected: @vocab.", array(
'@vocab' => $ignored_settings,
), array(
'langcode' => 'warning',
)));
}
return $form;
}