Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
We recently (better late then never) introduced menu_build_tree(). The menu block module could probably use this to build its menu trees. If for some reasons it cannot, menu_build_tree() can serve as a reference implementation of how to query, cache and build a menu tree, which definitely not easy to get right :)
Comment | File | Size | Author |
---|---|---|---|
#7 | 853462-7-menu_build_tree.patch | 1.64 KB | JohnAlbin |
#6 | menu_block.patch | 2.35 KB | eärendil |
Comments
Comment #1
JohnAlbinYep, this is on my radar. :-)
Comment #2
richsky CreditAttribution: richsky commentedWell, I'm wondering if it could allow me to use a unique id on the
<ul>
of my choice...since
Comment #3
JohnAlbinUnfortunately, there's a convoluted dependency for implementing this.
The recent Menu position modules uses a tricky pre-cache strategy of building and caching the menu tree before core or Menu block module requests it. Its completely hacky, but works in both D7 and D6.
If we implemented menu_build_tree in the 7.x-2.x branch of Menu block, menu position module would no longer work since it only works with root-level trees and not sub-trees.
The patch at #520106: Allow setting the active menu trail for dynamically-generated menu paths. would allow Menu position to dump its pre-cache strategy and start using those new APIs. Which would free up Menu block to use the menu_build_tree() functions. Since the patch isn't in Drupal 7.0, I'll have to roll a Menu block 7.x-2.0 without it. Moving to the 7.x-3.x branch.
Marking this as critical, since its blocking my plans to prepare parts of Menu block for Drupal 8.
Comment #4
JohnAlbinComment #5
JohnAlbinThis is unblocked now that Drupal 7 has finally fixed #520106: Allow setting the active menu trail for dynamically-generated menu paths..
Comment #6
eärendil CreditAttribution: eärendil commentedHere is a possible use of the menu_build_tree function in the module to help build the tree. I have attached a patch for review, but be careful as the code is still in development.
Comment #7
JohnAlbinRe-rolled #6 after #1937038: Use $max_depth parameter of menu_tree_all_data() and menu_tree_page_data() was committed.