You are here

function menutrails_settings_form in Menu TrailsMenu Trails 5

Same name and namespace in other branches
  1. 6 menutrails.module \menutrails_settings_form()

Form builder function for settings.

This is where menutrails rules are set. The interface here could definitely stand for some improvement. It's especially unhelpful for tagging vocabularies with lots and lots of terms.

1 string reference to 'menutrails_settings_form'
menutrails_menu in ./menutrails.module
Implementation of hook_menu().

File

./menutrails.module, line 100
Menutrails allows the assigment of "trails" which will keep menu items active for individual node views.

Code

function menutrails_settings_form() {
  $options = array(
    'NONE',
  );
  $options = $options + menu_parent_options($item['mid'], variable_get('menu_parent_items', 0));
  $node_types = node_get_types('names');
  $node_trails = variable_get('menutrails_node_types', array());
  if (module_exists('taxonomy')) {
    $vocabs = taxonomy_get_vocabularies();
  }
  $term_trails = variable_get('menutrails_terms', array());
  $form['description'] = array(
    '#type' => 'markup',
    '#weight' => '-100',
    '#value' => t('Use these settings to configure the "menu trails" for your nodes. This determines what menu items are activated when viewing an individual node. For instance, if you have a menu item for "Blog," you may want to have all blog posts fall under that menu.'),
    '#prefix' => '<p>',
    '#suffix' => '</p>',
  );
  $form['order'] = array(
    '#type' => 'markup',
    '#weight' => '-99',
    '#value' => t('<p>Menu trials are evaluated in the following order:</p> <ol><li>Node type</li><li>Taxonomy category</li><li>Node-specific menu setting</li></ol><p>In other words, category-based menu trails override node-type, and specific settings made on the node itself override both. Category-based menu trails are evaluated by weight in the order shown here, so settings in lower vocabularies take precidence.</p>'),
  );
  $form['menutrails_node_types'] = array(
    '#tree' => TRUE,
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#title' => t('Menu trails by node type'),
  );
  foreach ($node_types as $key => $value) {
    $form['menutrails_node_types'][$key] = array(
      '#type' => 'select',
      '#title' => t('Parent item for') . " {$value}",
      '#default_value' => $node_trails[$key],
      '#options' => $options,
    );
  }
  if (isset($vocabs)) {
    foreach ($vocabs as $vocab) {
      $form[$vocab->vid]['menutrails_terms'] = array(
        '#tree' => TRUE,
        '#type' => 'fieldset',
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
        '#title' => t('Menu trails by category:') . " {$vocab->name}",
      );
      $terms = taxonomy_get_tree($vocab->vid);
      foreach ($terms as $term) {
        $form[$vocab->vid]['menutrails_terms'][$term->tid] = array(
          '#type' => 'select',
          '#title' => t('Parent item for') . " {$term->name}",
          '#default_value' => $term_trails[$term->tid],
          '#options' => $options,
        );
      }
    }
  }
  return system_settings_form($form);
}