theme_nice_menu_primary_links is a nice little helper-function. It'd be nice to have one for secondary links as well, especially now that that comes in Drupal 6+ by default.

Comments

add1sun’s picture

Status: Active » Needs review
StatusFileSize
new1.41 KB

patch attached. not tested.

add1sun’s picture

Status: Needs review » Fixed

Added to HEAD.

chrisfromredfin’s picture

When secondary links source is set to primary links, theme_nice_menu_secondary_links still renders the top level (primary links). I would expect it to render the tree one-level below where you currently are (as theme('links', $secondary_links) does). Is this a poor expectation on my part?

I would think the function would need to check to see if the source for secondary is the same as the source for primary, and if so, custom-build $menu by kind of "shifting off" a level. I am thinking through an approach for that, but I don't know a ton about the 6x menuing system yet. If you have any insights, I would welcome them!

add1sun’s picture

ah, you mean actually using the relationship of things? hrm. yeah that isn't what is intended, but i can see the expectation. :/ I hadn't thought someone might do a primary menu and then want the secondary for primary to be a dropdown. I think that maybe nice_primary_menus was designed for that concept maybe. I'll have to look at it since i never played with it.

chrisfromredfin’s picture

OK I think I *might* have an OK solution. Before I submit it as a patch, I'd like to know if the approach is reasonable. Also, if you have any suggestions for the helper function names, etc.

(Or, perhaps you'd rather I just attach a patch... if so, let me know.)

The new theme_nice_menus_secondary_links():

function theme_nice_menus_secondary_links($direction = 'down', $depth = -1, $menu = NULL) {
  $menu_name = variable_get('menu_secondary_links_source', 'secondary-links');
  /*** NEW CODE ***/
  // if "secondary links" is just one level below primary, we have a special case  
  if (variable_get('menu_secondary_links_source', 'secondary-links') == variable_get('menu_primary_links_source', 'primary-links')) {
    $menu = _get_secondary();
  }
  /*** END NEW CODE ***/
  $output = theme('nice_menus', 0, $menu_name, 0, $direction, $depth, $menu);
  return $output['content'];
}

this code is largely borrowed from menu.inc's menu_navigation_links()

// Secondary Links Menu Helper
function _get_secondary() {
  // Get the menu hierarchy for the current page.
  $level = 1;
  $tree = menu_tree_page_data('primary-links');

  // Go down the active trail until the right level is reached.
  $keys = array_keys($tree);
  $numshifts = -1;  
  while ($level-- > 0 && $tree) {
    // Loop through the current level's items until we find one that is in trail.
    while ($item = array_shift($tree)) {
      $numshifts++;
      if ($item['link']['in_active_trail']) {
        // If the item is in the active trail, we continue in the subtree
        break;
      }
    }
  }

  $tree = menu_tree_all_data('primary-links');
  return $tree[$keys[$numshifts]]['below'];
}

I also realize that I could put this helper function at my theme level, like in template.php, and just call theme_nice_menus_secondary_links() or a similar nice_menus theme function, passing it this custom $menu. So I'm not sure if you think that this should be part of your module or a snippet for people to dump in their own template.php. Based on personal experience, as you know, I expected it to do this.

Audiowave’s picture

im trying to have my secondary links as dropdown menus, they have no relation to my primary links. Does the latest version have this feature or do i need to run the patch from post?

Thanks.

chrisfromredfin’s picture

the -dev version of nice_menus will support what you need natively, my code is only if secondary links is set to primary links

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.