You are here

function taxonomy_defaults_form in Taxonomy Defaults 5

Same name and namespace in other branches
  1. 6.2 taxonomy_defaults.admin.inc \taxonomy_defaults_form()
  2. 6 taxonomy_defaults.admin.inc \taxonomy_defaults_form()
  3. 7 taxonomy_defaults.admin.inc \taxonomy_defaults_form()

Defines the page at admin/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.module, line 90
Taxonomy defaults - allows assignment of default terms to node types, either

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);
      $form[$type][$vid]['active'] = array(
        '#type' => 'checkbox',
        '#title' => $activevocab ? t('active') : t('not active'),
        '#default_value' => variable_get("taxdef_{$type}_{$vid}_active", FALSE),
        '#weight' => -16,
      );
      $form[$type][$vid]['select'] = taxonomy_form($vid, variable_get("taxdef_{$type}_{$vid}", 0));
    }
    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'),
      );
    }
    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/taxonomy/add/vocabulary'),
        )),
      );
    }
  }
  return $form;
}