Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 292007

_menu_load_objects() is not always called when building menu trees

$
0
0

Okay, this has to be the weirdest drupal bug I have come to see thus far and I have to admit I didn't see this thing all the way through, partly because of it's quirkiness, partly because of a deadline I already busted.

I wrote a module which enables the site admin to create menu-blocks (completely independent from the module with that name!) that display the menu items with optional images and orders the items with some taxonomy-magic.

Now I wanted to display the main menu two times, one time as a dropdown menu like described above, and one time in the footer.
Everything works fine with that, output is just like expected. But, and this is the strange thing: If there are two blocks, the following type of error occurs for every menu-item that links to a node:

Notice: Trying to get property of non-object in node_page_title() (Zeile 2109 von /var/www/localhost/htdocs/catcruising/www/modules/node/node.module).

I've tracked this down to menu_build_tree, which I use in order to get the menu that is to be rendered.

The trace goes roughly like this: menu_build_tree -> menu_tree_check_access -> _menu_tree_check_access -> _menu_link_translate -> _menu_item_localize

As far as I can tell the following line in _menu_item_localize is the culprit:

<?php
$item
['title'] = call_user_func_array($callback, menu_unserialize($item['title_arguments'], $map));
?>

For some reason I cannot grasp, the second time around the node-titles are tried to be translated, calling node_page_title with the argument ($node) being a simple integer, instead of a node-object.

In case it's not yet obvious: It seems that you cannot call menu_build_tree for the same menu multiple times in the same page request.

My current workaround for this problem is setting a global variable with the menu tree, which works just fine. But I think if I tried to output the same menu once with the default drupal means and once using my module (or another) this bug would surface again.


Viewing all articles
Browse latest Browse all 292007

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>