OK, this might be a bit specialized, but there was no way to get at the menu tree using core D7 alter hooks or any preprocessing hooks. We had a need to preprocess the raw menu tree before it is rendered (which is all you get in template_preprocess_menu_tree, not the structure tree like you would expect from the function name).

This small patch adds the following alter hooks to site_map that are called immediately before a menu tree is rendered:

  • hook_site_map_menu_tree_alter(&$tree, $menu)
  • hook_site_map_menu_tree_MID_alter(&$tree, $menu)

The menu ID is munged just like most machine name based callbacks, converting anything non-numeric, non-alpha, and not underscores to underscores (e.g. "main-menu" becomes "main_menu").

Patch attached below, hopefully someone else will have a use for it - and it might not be a bad feature to port to the module.

#1 site_map-alter_hooks-1588988-01.patch702 bytesarpieb


arpieb’s picture

Status: Active » Needs review
702 bytes

Patchfile for alter hooks against 7.x-1.x branch

darrell_ulm’s picture

Hey thank you. There is another request for this and I believe a patch. Security implications, if any?


arpieb’s picture

I searched for "alter" in the issue queue, not "hook" - just found it over here #1349202: Allow other modules to modify the menu structure.

In reviewing that patch, it doesn't leverage the standard D7 alter mechanism, and also doesn't allow for specific menu-id based alter hooks to be invoked (e.g. hook_site_map_menu_tree_alter and hook_site_map_menu_tree_MID_alter). This patch is a bit more complete in addressing the feature.

As for security implications - since it's not using or displaying any user-contributed content and not bypassing any menu permissions, it should have no impact on the security of the module. Of course, any contrib module that implements the alter hook could muck something up, but that's not a security concern for this module (if that were the case, D7 core would be considered insecure... ;)

darrell_ulm’s picture

Good points for when anyone looks at the patch. Thanks for the update.

john.oltman’s picture

Issue summary: View changes
Status: Needs review » Fixed

In the new 7.x-1.1 release

Status: Fixed » Closed (fixed)

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