The Menu Node Edit module enables specific menu items to be defined as 'sections' of a site.

The Menu Block allows for navigation to be built so that the menu displayed is chosen by '<the menu selected by the page>'. There is also a place where you can set the Starting Level.

Does someone know of a way to combine the functionality of these two modules to allow the Starting Level to be the 'section' closest to the page? (I figure sections may be nested in some sites)

What I tried

I tried using several menu blocks: “Links (level 1+)”, “Links (level 2+)”), “Links (level 3+)”, etc. I ordered the blocks from deepest to shallowest and was going to set the shallower level blocks to hide if a deeper one was present.

I ran into trouble in two places that combined to sink my idea:

  1. The 'section head' comes at different places in different areas, sometimes it is at level 3 and sometimes at 5.
  2. When section heads have 2+ levels underneath, and a user is on a page 2+ levels down from the section head, the deepest block cuts out links to the grandparent that is the section head.

Any help would be greatly appreciated!

Comments

agentrickard’s picture

I had to do something like this, I think, and ended up replacing the Menu Block with a custom block, though I think hook_menu_block_alter() (?) may work. This code is dependent on Menu Block module:

function custom_block_view() {
  if(arg(0) == 'admin') {
    return;
  }
  // Determine the current menu section.
  $path = $_GET['q'];
  $item = db_fetch_array(db_query("SELECT ml.* FROM {menu_links} ml INNER JOIN {menu_custom} mc ON ml.menu_name = mc.menu_name WHERE ml.link_path = '%s'", $path));

  if (!empty($item)) {
    // We walk the depth tree in inverse order to find the lowest parent.
    for ($i = $item['depth']; $i >= 1; $i--) {
      $parent = db_result(db_query("SELECT mlid FROM {menu_node_edit} WHERE mlid = %d", $item["p$i"]));
      if (!empty($parent)) {
        break;
      }
    }
  }

  $section =  db_fetch_object(db_query("SELECT * FROM {menu_links} WHERE mlid = %d", $parent));

  menu_tree_prune_tree($tree, 0, $section);
  // Now, subordinate that tree to the section parent.
  $new_tree = array();
  $new_tree['5000 '. $section['link_title']] = array(
    'link' => menu_get_item($section['link_path']),
    'below' => $tree,
  );
  $block = array(
    'subject' => '',
    'content' => ($item['menu_name'] != 'navigation') ? menu_block_tree_output($new_tree) : '',
  );
  return $block;
}

This is abstracted from some unreleased private code, so it may need some tweaking.

fullerja’s picture

Thank you so much for posting this.

I tried dropping the code into a Block with PHP input format and it doesn't work immediately. I am working to get it running. I am not very good at PHP, but here is the time to learn.

I think this is a great functionality, please let me know if there is anything I can do to help get it released as part of the/a module.

agentrickard’s picture

I don't think you can put this into a block. I think you need hook_block().

http://drupal.org/patch/create to contribute.

agentrickard’s picture

Category: support » feature
Status: Active » Needs work