Closed (fixed)
Project:
Drupal core
Version:
7.x-dev
Component:
menu system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
3 Jul 2009 at 18:03 UTC
Updated:
5 Mar 2010 at 18:00 UTC
Jump to comment: Most recent file
Comments
Comment #1
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 commentedfirst pass here - passing an array into function menu_tree_data() since that makes the functions more re-usable
Comment #3
pwolanin commentedfirst pass here - passing an array into function menu_tree_data() since that makes the functions more re-usable
Comment #5
damien tournoud commentedI suggest walking the array in the normal order and using unset().
Comment #6
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 commentedWhy not:
Comment #8
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 commentedA better pass - allows for radicial simplification of _menu_tree_data()
Comment #11
pwolanin commentedoops - forgot to use --no-prefix
Comment #12
pwolanin commentedComment #14
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 commentedI think the problem was that book_menu_subtree_data() had a bug- failed to rename a variable.
Comment #18
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 commentedmore feedback from chx, leading to improved and expanded code comments to clarify the algorithm.
Comment #21
pwolanin commentedslight additional clarification
Comment #22
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 commentedWhat am I missing here? It seems like we're just making a copy of $result?
Comment #26
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 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 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 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