You are here

function jump_menu in Better Jump Menus 8

Same name and namespace in other branches
  1. 6 jump_menu.module \jump_menu()
  2. 7 jump_menu.module \jump_menu()

Output a core menu as a select jump menu.

1 call to jump_menu()
_jump_menu_render_block in ./jump_menu.module
Abstract block rendering to be more flexible about when/how this happens.
2 string references to 'jump_menu'
jump_menu_form_block_admin_configure_alter in ./jump_menu.module
Implements hook_form_FORM_ID_alter(). Add custom options to block editing forms.
_jump_menu_render_block in ./jump_menu.module
Abstract block rendering to be more flexible about when/how this happens.

File

./jump_menu.module, line 17
Make use of the CTools jump menu and grabs from an existing menu. See: modules/ctools/includes/jump-menu.inc NOTE: Menu items must be checked as "expanded" for traversing to work.

Code

function jump_menu($menu, $parent, $btn = FALSE, $max_depth = 0, $choose = 'Select a destination', $current = FALSE) {
  ctools_include('jump-menu');

  // Load up the menu.
  $menu = menu_tree_all_data($menu);

  // Trim to the needed portion, start at parent menuID.
  foreach ($menu as $m) {

    // The mlid is i18n tranlsation friendly.
    if ($m['link']['mlid'] == $parent) {
      $menu = $m['below'];
      break;
    }
  }

  // Initialize for building.
  $depths = array(
    'current' => 1,
    'max' => $max_depth,
  );
  $targets = array();

  // Build the jump options from the menu.
  _jump_menu_create_options($targets, $menu, $depths);

  // Output...
  if (count($targets) == 0) {
    return 'Jump menu contains no items!';
  }
  else {
    $options = array();

    // Handle button option.
    if ($btn) {
      $options['hide'] = FALSE;
      $options['button'] = $btn;
    }
    else {
      $options['hide'] = TRUE;
    }

    // Place initial select option value.
    $options['choose'] = t($choose);

    // Set current location if desired.
    if ($current) {
      $current_path = base_path() . request_path();
      if (!empty($current_path)) {
        $options['default_value'] = $current_path;
      }
    }

    // Other available options...
    // 'title' => The text to display for the #title attribute.
    // 'description': The text to display for the #description attribute.
    // 'image': If set, an image button will be used instead, and the image set to this.
    // 'inline': If set to TRUE (default) the display will be forced inline.
    return drupal_render(drupal_get_form('ctools_jump_menu', $targets, $options));
  }
}