You are here

function menutrails_menutrails_settings in Menu TrailsMenu Trails 6

Implementation of hook_menutrails_settings().

Allows other modules to define their own menutrail behavior.

Please define your input as a fieldset and do not assign a weight. This will keep the groups of menutrails settings in order.

Parameters

$options: Options array to be used by other modules to define their own menutrails.

Return value

A form element (or array) for the menutrails system settings form.

File

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

Code

function menutrails_menutrails_settings($options) {
  $form = array();
  $node_types = node_get_types('names');
  $node_trails = variable_get('menutrails_node_types', array());
  $vocabs = module_exists('taxonomy') ? taxonomy_get_vocabularies() : array();
  $term_trails = variable_get('menutrails_terms', array());
  $form['menutrails_node_types'] = array(
    '#tree' => TRUE,
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#title' => t('Node types'),
  );
  foreach ($node_types as $key => $value) {
    $form['menutrails_node_types'][$key] = array(
      '#type' => 'select',
      '#title' => t('Parent item for') . " {$value}",
      '#default_value' => isset($node_trails[$key]) ? $node_trails[$key] : NULL,
      '#options' => $options,
    );
  }
  foreach ($vocabs as $vocab) {

    // Tagging gets out of hand too fast, so we disallow.
    if ($vocab->tags != 1) {
      $form[$vocab->vid]['menutrails_terms'] = array(
        '#tree' => TRUE,
        '#type' => 'fieldset',
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
        '#title' => t('Categories: @vocabulary', array(
          '@vocabulary' => $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', array(
            '@term' => $term->name,
          )),
          '#default_value' => isset($term_trails[$term->tid]) ? $term_trails[$term->tid] : NULL,
          '#options' => $options,
        );
      }
    }
  }

  // Organic groups support.
  if (module_exists('og')) {
    $form['menutrails_og'] = array(
      '#type' => 'fieldset',
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#title' => t('Organic groups'),
      '#description' => t('Settings for nodes withing Organic groups: these override node and taxonomy settings.'),
    );
    $form['menutrails_og']['menutrails_og_sub_pages'] = array(
      '#type' => 'checkbox',
      '#title' => t('Use group node menu trail for pages in groups'),
      '#default_value' => variable_get('menutrails_og_sub_pages', TRUE),
      '#description' => t('Use menutrails present for an organic group node for OG sub pages (e.g. "manage subscription" or "members").'),
    );
    $form['menutrails_og']['menutrails_og_post_default'] = array(
      '#type' => 'select',
      '#title' => t('Default menu trail for all nodes with group audience'),
      '#default_value' => variable_get('menutrails_og_post_default', 0),
      '#description' => t('Default menu trail for any posts in a group.'),
      '#options' => $options,
    );
    $form['menutrails_og']['menutrails_og_node'] = array(
      '#type' => 'fieldset',
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#tree' => TRUE,
      '#title' => t('Individual organic group trails'),
      '#description' => t('Specific trails for posts within specific groups.'),
    );
    $result = db_query('SELECT n.nid, n.title FROM {node} n INNER JOIN {og} og ON n.nid = og.nid ORDER BY n.title');
    $og_trails = variable_get('menutrails_og_node', array());
    while ($node = db_fetch_object($result)) {
      $form['menutrails_og']['menutrails_og_node'][$node->nid] = array(
        '#type' => 'select',
        '#title' => t('Group @group', array(
          '@group' => $node->title,
        )),
        '#default_value' => isset($og_trails[$node->nid]) ? $og_trails[$node->nid] : NULL,
        '#options' => $options,
      );
    }
    $form['menutrails_og']['menutrails_og_group_menu'] = array(
      '#type' => 'checkbox',
      '#title' => t("Use group's menu item for posts"),
      '#default_value' => variable_get('menutrails_og_group_menu', FALSE),
      '#description' => t('If a specific group node has an assigned menu item, use this as the trail for nodes which have that group as an audience. If present, this will override all other group settings.'),
    );
  }
  return $form;
}