You are here

function taxonomy_menu_form_alter in Taxonomy menu 6.2

Same name and namespace in other branches
  1. 7 taxonomy_menu.module \taxonomy_menu_form_alter()

Implementation of hook_form_alter().

Modify the form at admin/content/taxonomy/edit/vocabulary/xx. We add our taxonomy_menu options in here on a per-vocab basis.

File

./taxonomy_menu.module, line 25
It Generates menu links for all selected taxonomy terms

Code

function taxonomy_menu_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'taxonomy_form_vocabulary') {

    // choose a menu to add link items to.
    $menus = menu_get_menus();
    array_unshift($menus, t('- Disabled -'));

    // options for path if tokens are not enabled
    $paths = _taxonomy_menu_get_paths();
    $form['taxonomy_menu'] = array(
      '#type' => 'fieldset',
      '#collapsible' => TRUE,
      '#title' => t('Taxonomy menu'),
      '#weight' => 10,
      '#tree' => TRUE,
    );

    // this turns the vocab terms into menu items
    $item['mlid'] = 0;
    $menu_items = menu_parent_options(menu_get_menus(), $item);
    array_unshift($menu_items, '= DISABLED =');
    $default = variable_get('taxonomy_menu_vocab_menu_' . $form['vid']['#value'], NULL) . ':' . variable_get('taxonomy_menu_vocab_parent_' . $form['vid']['#value'], NULL);
    if (!isset($menu_items[$default])) {
      $default = 0;
    }
    $form['taxonomy_menu']['vocab_parent'] = array(
      '#type' => 'select',
      '#title' => t('Menu location'),
      '#default_value' => $default,
      '#options' => $menu_items,
      '#description' => t('The menu and parent under which to insert taxonomy menu items.'),
      '#attributes' => array(
        'class' => 'menu-title-select',
      ),
    );
    $form['taxonomy_menu']['path'] = array(
      '#type' => 'select',
      '#title' => t('Menu path type'),
      '#default_value' => variable_get('taxonomy_menu_path_' . $form['vid']['#value'], 0),
      '#options' => $paths,
      '#description' => t('The path will be taxonomy/term/tid if <em>Default</em> has been selected.<br />The menu path will be passed through drupal_get_path_alias() function so all aliases will be applied.'),
    );

    // get taxonomy menu form options
    $form['taxonomy_menu']['options'] = _taxonomy_menu_create_options($form['vid']['#value']);

    // rebuild the menu
    $form['taxonomy_menu']['options']['rebuild'] = array(
      '#type' => 'checkbox',
      '#title' => t('Select to rebuild the menu on submit.'),
      '#default_value' => 0,
      '#weight' => 20,
      '#description' => t('Rebuild the menu on submit. <strong>Warning</strong>: This will delete then re-create all of the menu items. Only use this option if you are experiencing issues like missing menu items or other inconsistencies.'),
    );

    // move the buttons to the bottom of the form
    $form['submit']['#weight'] = 49;
    $form['delete']['#weight'] = 50;

    // add an extra submit handler to save these settings
    $form['#submit'][] = 'taxonomy_menu_vocab_submit';
  }
}