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.
Splitting off from #484820: Initial D7UX admin header
You currently can't get a slice of a menu down to a certain depth, only all items below a certain point in the tree - it might make sense to add a $depth param to menu_tree_all_data() to just be able to get certain levels of the tree at any one time.
Comment | File | Size | Author |
---|---|---|---|
#29 | menu-api-fixes-509584-29.patch | 15.05 KB | pwolanin |
#28 | menu-api-fixes-509584-28.patch | 14.37 KB | pwolanin |
#21 | menu-api-fixes-509584-20.patch | 14.35 KB | pwolanin |
#20 | menu-api-fixes-509584-19.patch | 14.31 KB | pwolanin |
#18 | menu-api-fixes-509584-18.patch | 13.94 KB | pwolanin |
Comments
Comment #1
pwolanin CreditAttribution: pwolanin commentedWe shoudl pull in some of the straigh menu APi fixes from #483614: Better breadcrumbs for callbacks, dynamic paths, tabs to make that issue simpler to deal with.
Comment #2
pwolanin CreditAttribution: pwolanin commentedfirst pass here - passing an array into function menu_tree_data() since that makes the functions more re-usable
Comment #3
pwolanin CreditAttribution: pwolanin commentedfirst pass here - passing an array into function menu_tree_data() since that makes the functions more re-usable
Comment #5
Damien Tournoud CreditAttribution: Damien Tournoud commentedI suggest walking the array in the normal order and using unset().
Comment #6
pwolanin CreditAttribution: pwolanin commented@Damien - but pop is such a nice function name and does just what we want :)
I'm really not such how do do what you suggest in as simple a way. To me this seems ugly and much harder to understand by comparison:
while ($data = each($result)) {
unset($result[$data[['key']);
$item = $data['value'];
}
I chose a reverse and pop because array_unshift() is a rather more expensive operation than pop.
Comment #7
Damien Tournoud CreditAttribution: Damien Tournoud commentedWhy not:
Comment #8
pwolanin CreditAttribution: pwolanin commented@Damien - still rather ugly imho - in either case we need to pass the array by reference when we do the recursion. What happens when we come out of the recursive call and we have unset the the array element that the current foreach loop thinks is the current element? I hope PHP handles that gracefully?
Comment #9
pwolanin CreditAttribution: pwolanin commentedA better pass - allows for radicial simplification of _menu_tree_data()
Comment #11
pwolanin CreditAttribution: pwolanin commentedoops - forgot to use --no-prefix
Comment #12
pwolanin CreditAttribution: pwolanin commentedComment #14
pwolanin CreditAttribution: pwolanin commentedfixed book and menu module.
Comment #16
catchMissing documentation for the $max_depth param.
Also missing @param documentation.
Otherwise looks good apart from that one fail, I don't fully get all the changes here, especially not this evening, but the gnarliest bit is at least a lot less gnarly than what's in there now.
This review is powered by Dreditor.
Comment #17
pwolanin CreditAttribution: pwolanin commentedI think the problem was that book_menu_subtree_data() had a bug- failed to rename a variable.
Comment #18
pwolanin CreditAttribution: pwolanin commentedremove unneeded $result->setFetchMode() calls, fix comment
Comment #19
sunIf those menu tree data functions would additionally allow to specify a starting menu link instead of a menu name, that would heavily trivialize admin_menu as well as http://drupal.org/project/menu_block (which contains some raw menu_*() forks that should be in core)
Comment #20
pwolanin CreditAttribution: pwolanin commentedmore feedback from chx, leading to improved and expanded code comments to clarify the algorithm.
Comment #21
pwolanin CreditAttribution: pwolanin commentedslight additional clarification
Comment #22
chx CreditAttribution: chx commentedVery nice code cleanup! I am surprised this could be simplified so much. I got a headache when coded the original, however, it's not an easy thing, this tree traversal because of the way it is. Some time and a "new" coder helped it :)
Comment #24
webchickOh, testing bot...
Comment #25
Dries CreditAttribution: Dries commentedWhat am I missing here? It seems like we're just making a copy of $result?
Comment #26
pwolanin CreditAttribution: pwolanin commented@Dries - $reslt is a query result object that implements the Iterator interface so we can call foreach() one it (but not other array functions). By doing the foreach first, we allow the menu_tree_data() function to take a more generic array as a parameter.
Comment #28
pwolanin CreditAttribution: pwolanin commentedfixed a very minor 1-line merge conflict in book.test (where I am fixing a typo in the test that was failing above).
Comment #29
pwolanin CreditAttribution: pwolanin commentedminor doxygen changes per Dries and added type hinting to the arguments of menu_tree_data()
Comment #30
webchickI think this PHPDoc is sufficient. While I too found this confusing, it's not the job of menu API code to document DBTNG, and the docs that talk about a query result object are enough of a breadcrumb for me to go off searching if I need to for further clarification.
This looks like a nice clean-up to make the menu API more comprehensible to mere mortals. :)
Committed to HEAD. Needs updating in the documentation.
Comment #31
samuelsov CreditAttribution: samuelsov commentedmenu_tree_data is the only function which needs a conversion between Drupal 6 and Drupal 7 because the depth param is optional.
Documented in http://drupal.org/update/modules/6/7#menu_tree_data
#d7csmtl