I think it's the most common use-case: integrate nice_menus with the top main-menu of an existing theme.
So, let's say we use a child theme of Bartik containing the bare minimum (only intended to override some properties).
The default Bartik page.tpl.php contains the following:

<?php if ($main_menu): ?>
      <div id="main-menu" class="navigation">
        <?php print theme('links__system_main_menu', array(
          'links' => $main_menu,
          'attributes' => array(
            'id' => 'main-menu-links',
            'class' => array('links', 'clearfix'),
          ),
          'heading' => array(
            'text' => t('Main menu'),
            'level' => 'h2',
            'class' => array('element-invisible'),
          ),
        )); ?>

where $main_menu comes from includes/theme.inc / template_preprocess_page() when it calls menu_main_menu().

  • First note: this function being called unconditionally, it would be a perf' penalty to make yet another call to retrieve the menu to get the children.
  • Second note: menu_main_menu() will call menu_navigation_links("main-menu") which only returns the 1st level entries (whatever second argument is passed...)

Let's forget the above note about performance for now,

  • The first step is to override the menu array; hook__preprocess_page(&$variables) setting $variables['main_menu'] may be a good candidate for this but... which function to use to retrieve a deeper but similar structure than what menu_main_menu() returns ? menu_tree() ?
  • The second step is to control <ul> (id and classes) and override <li> (classes), thus using the themable links__system_main_menu

But here seem to come big troubles of menu_tree() to replace menu_main_menu(), at least because rendering recursively the menu without control on the top level <ul> makes all of them getting the id what is obviously wrong.
So, let's believe that menu_tree() is the good candidate, how to theme it ?
The problem is obviously that the structure it returns contains #theme_wrappers == menu_tree__main_menu whatever the <ul> depth is.
Can we try to change it so that the first level #theme_wrappers is a themable we can control ?

follow-up coming.

Comments

drzraf’s picture

Ok, speaking about the issue of the <ul> id attribute uniqueness.
using the #theme_wrappers approach may gives some success.
When we theme the main-menu using hook_links__system_main_menu, we can actually override the value of the top-level #theme_wrappers array key (which is the one which handles the top-level <ul>).
So that we can use our specific function for the top-level <ul>, let's call it "hook_menu_tree__main_menuTOP".
Of course we have to declare this using hook_theme, so ending up with:

function hook_theme() {
  return array( 'menu_tree__main_menuTOP' => array( 'render element'  => 'element' ) );
}

function hook_links__system_main_menu($variables) {
  if ($variables['attributes']['id'] == 'main-menu-links') {
    $pid = variable_get('menu_main_links_source', 'main-menu');
    $tree = menu_tree($pid);
    $tree['#theme_wrappers'][0] = 'menu_tree__main_menuTOP';
    return drupal_render($tree);
  }
  return theme_links($variables);
}

function hook_menu_tree__main_menuTOP($variables) {
    return '<ul class="menu clearfix nice-menu nice-menu-down" id="nice-menu-42">';
}

Of course nothing stops us to use a $static in the *menuTOP() function to defines incremental id.

So, still following the Customization section of nice_menus/README.txt we will try to set the class attributes in the <li> which is the second (and hopefully last) issue to deal with...
in the next comment.
But ! we can already see a huge problem coming : Bartik and nice_menus expect a different id attribute value for the top-level </ul>, that a shame they don't use classes... troubles ahead.

drzraf’s picture

From grep'ing a bit nice-menus css it seems that the id is superfluous. So we can skip this directive of the README and keep the theme default (main-menu-links).
But then there are multiple problems caused by properties of nice_menus_default.css which garbled the default style, specifically :

ul.nice-menu-down li {
   border-top: 1px solid #CCCCCC;
}

ul.nice-menu li {
    background-color: #EEEEEE;
    border-style: none solid solid;
}

Then, sublevel <li> are also affected by some properties, eg:

ul.nice-menu ul {
 top: 1.8em;
}

which seems wrong for Bartik (2.4em would be better).
We also would need to round the borders of subitems, eg:

    border-bottom-left-radius: 8px;
    border-bottom-right-radius: 8px;

That means #main-menu-links ul.menu a because as stated in the above comment, sub<ul> keep their default menu class.
The background color will have to be touched too, but let's postpone all of this because we still have to
solve the 2nd issue of the topic: adding custom classes (like menuparent) to the individual <li> which, unlike the <ul> id are of importance for the nice_menus css.

eojthebrave’s picture

@drzraf. I'm not entirely sure what you're trying to do here but if I'm reading this correctly you're trying to display the nice menu's drop down in the header area of your bartik theme and have it look a bit more Bartik like?

If that's the case I would actually recommend making a sub-theme of Bartik and editing the page.tpl.php file and just replacing the code that prints out the main menu there (shown in your first comment) with something like this:

print theme('nice_menus_main_menu');

Then you can also copy the style.css file from Bartik and override it in your sub-theme and tweak class / ID names as necessary.

You can see more about the theme functions available here: http://drupal.org/node/236418

astonvictor’s picture

Status: Active » Closed (outdated)

I'm closing it because the issue was created a long time ago without any further steps.

if you still need it then raise a new one.
thanks