I have the module installed and configured with blocks set to 0 intending to skip the block code overhead and use theme functions. I had primary_links working with the following code:

<div id="nice-primary" class="clear-block">
      <?php print theme_nice_menu_primary_links('down', NULL); ?> 
</div> <!-- /#primary -->

But when I tried to add the navigation menu:

            <div id="nice-primary" class="clear-block">
             <?php print theme_nice_menu_primary_links('down', NULL); ?> 
              <div id="nice-navigation" > 
                <?php print theme('nice_menu', 0, 'navigation', NULL, 'down'); ?> 
              </div>  <!-- /#navigation -->
            </div> <!-- /#primary -->

I get the word Array will the navigation menu should be. See nice_menu_output.png attached
The problem is clearly with the theme() function usage as

            <?php print theme('nice_menu', 0, 'primary_links', NULL, 'down'); ?>

results in Array as well as shown in nice_menu_output_2.png

Comments

fathershawn’s picture

StatusFileSize
new600 bytes
new3.72 KB

Trying to attach the screen shot graphics files again as I don't see them here.

fathershawn’s picture

I went to look at the code in the module for the theme_nice_menu function. If both conditions for $menu_tree fail nothing gets assigned to $output. So I setup the following debug code at line 360 before the If statements:

  $f = fopen("/sites/drupal/nice_menu_debug.txt", "a"); 
  if ($menu_tree) {
     fwrite($f, \n . $menu_tree); 
  } else {
     fwrite($f, \n . "menu_tree is null");
     fwrite($f, \n . $output);
  }
  fclose($f);

Which resulted in:

menu_tree is null
Array

So now to figure out why $menu_tree is empty....

fathershawn’s picture

Component: Theme Compat » Code
Category: support » bug
Priority: Normal » Critical

Well, I've changed this to a bug report and apologize in advance if what looks like a bug is merely a limitation in my growing php knowledge.

$menu_tree is not declared anywhere in the module, nor a search through my drupal install find it anywhere in core, so it doesn't look like it's included from somewhere else. Is there some code missing?

fathershawn’s picture

OK, so I missed the obvious...

if ($menu_tree = theme('nice_menu_tree', $menu_name, $mlid, $menu)) {

Is supposed assign the results of the theme function to $menu_tree and skip the block if the function returns NULL.
So I need to track down why the function returns NULL.

So, I adapted the primary links theme function as follows:

function theme_nice_menu_other_links ($id = 0, $menu_name, $mlid = NULL, $direction = 'down', $menu = NULL) {
  $menu_source = 'menu_' . $menu_name . '_source';
  $menu_name = variable_get($menu_source, $menu_name);
  $output = theme('nice_menu', 0, $menu_name, 0, $direction, $menu);
  return $output['content'];
}

Which output a Nice Menu of the Navigation menu when called as theme_nice_menu_other_links(0, 'navigation', NULL, 'down'). So there must be something about the menu_name being passed to theme_nice_menu in the original which is causing theme_nice_menu_tree to choke.

fathershawn’s picture

Category: bug » support
Priority: Critical » Normal

The theme_nice_menu function works fine when called by theme_nice_menu_primary_links so its not a bug.

fathershawn’s picture

OK. I'm back to being stumped. I added some debug code to theme_nice_menu to try to understand why it works in some situations and not others. The debug version of the function looks like:

function theme_nice_menu($id, $menu_name, $mlid, $direction = 'right', $menu = NULL) {
  $output = array();
    /* Debug code begins here */
    $f = fopen("/Users/shawn/Sites/drupal/menu_source.txt", "a"); 
       fwrite($f, "id is " . $id . " ,"); 
       fwrite($f, "menu_name is " . $menu_name . " ,");
       fwrite($f, "mlid is " . $mlid . " ,");
       fwrite($f, "direction is " . $direction . " ,");
       fwrite($f, "menu is " . $menu . " \n");
    fclose($f);
  /* debug code ends. */

  if ($menu_tree = theme('nice_menu_tree', $menu_name, $mlid, $menu)) {
    if ($menu_tree['content']) {
      $output['content'] = '<ul class="nice-menu nice-menu-'. $direction .'" id="nice-menu-'. $id .'">'. $menu_tree['content'] .'</ul>'."\n";
      $output['subject'] = $menu_tree['subject'];
    }
  }
  return $output;
}

So theme_nice_menu_primary_links calls theme_nice_menu and the following is dumped in the file:

id is 0 ,menu_name is primary-links ,mlid is 0 ,direction is down ,menu is

When the following code is executed in page.tpl.php to call the function shown above

print theme_nice_menu_other_links(0, 'navigation', 0, 'down'); 

the file dump is:

id is 0 ,menu_name is navigation ,mlid is 0 ,direction is down ,menu is

And a proper Nice Menu of the navigation menu is generated.

When the standard function call is executed in page.tpl.php:

print theme_nice_menu(0, 'navigation', 0, 'down'); 

the file dump is:

id is 0 ,menu_name is navigation ,mlid is 0 ,direction is down ,menu is

and the result is the word Array instead of the menu.

Both sets of parameters look the same to me and so I can't figure out why it doesn't work when called directly. In the meantime, I've worked around the problem by adding a custom function to my template.php:

/* Workaround to get the Navigation menu to theme as a Nice Menu */
function discerning_nav_links($direction = 'down', $menu = NULL) {
  $menu_name = variable_get('menu_navigation_source', 'navigation');
  $output = theme('nice_menu', 0, $menu_name, 0, $direction, $menu);
  return $output['content'];
}
Standart’s picture

Possibly your problem occurs because you don't output the right part of what the theme function returns. As in http://drupal.org/node/236418 which is linked from the project page you have to output $menu['content'] like so:

$menu = theme('nice_menu', 1, 'menu-custom', NULL, 'left');
print $menu['content'];

This is the intended usage.

Standart’s picture

Status: Active » Fixed

Please re-open if this doesn't fix your problem.

Status: Fixed » Closed (fixed)

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

fathershawn’s picture

Thank you so much for the tutorial! Changed my page.tpl.php code to:

 $navMenu = theme('nice_menu', 0, 'navigation', NULL, 'down');
                     print($navMenu['content']);
               

And it works exactly as I expected! So I was able to remove the custom theme function and simplify the setup! This ethos of helping one another is what's great about the Drupal community!