Menu items sort order not respecting weight parameter
| Project: | Sympal book menu |
| Version: | 4.7.x-1.0 |
| Component: | Menu implementation |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
The module is working fine to generate menu items from a book, however it doesn't support the 'weight' property of the items, so the menu items are displayed in a different order to the book pages in a complex book.
I tried simply adding the weight parameter to the array returned in the hook_menu function and, although the array is correctly sorted, the final menu isn't. So, to be honest, this is probably more of a problem with the menu system (or my lack of understanding of it) than with this module.
The module code to build the array looks like this:
$toc[$node->nid]['title'] = $node->title;
$toc[$node->nid]['path'] = $path .'/'. $node->nid;
$toc[$node->nid]['callback'] = 'book_menu_callback';
$toc[$node->nid]['callback arguments'] = array('node' => $node);
$toc[$node->nid]['weight'] = intval($node->weight); // added this line
$toc[$node->nid]['access'] = TRUE;
I've reset the menu cache - indeed, deleted and rebuilt the menu from scratch - to see if that helped, but the menu system is obstinately ignoring my attempts to sort by weight...

#1
marked as feature request. Sounds like a good, valueble one.
#2
Hi,
Thanks for the update. As I said in the request, when I do a print_r of the menu items array that the module outputs, everything looks OK - the book pages are correctly sorted by weight at each level - so the recursive function seems to be working OK. So, I'm not sure if the problem stems from my clumsy attempt to add the 'weight' property to the array, or with the way the Drupal menu system deals with it.
If you have any pointers to where the problem might lie, I'm happy to keep hacking away at this...
Matthew
# UPDATE #
OK, so, after continuing to hack away at en entirely different problem, this now appears to be working. But I'm not quite sure why, or when things sorted themselves out. Rebuilding the menu from scratch didn't seem to help the other day, but having done another reset of the menu items, the now appear to be sorted by weight - Hurrah! Except, I'm not sure why - dammit!
Anyway, it seems like that extra line I added with the weight parameter was enough. I think I also saw a patch for creating the 'info' file to make the module compatible with D5, which is what I did to get it working. It would be good to update the module to 5.x compatible, if possible.
#3
OK, so just to tidy things up: The change to make the weight-sorting work was the addition of this line:
$toc[$node->nid]['weight'] = intval($node->weight);... after line 54. Not sure if the intval() is strictly required, but it's working, so I will mark this issue as fixed.
I would upload a patch, but as a Subversion user I have no idea how to prepare a CVS patch (something else I need to learn about Drupal - sigh!).
#4
hey, if *you* fixed it locally, that does not mean that the issue is fixed :).
#5
Well, *my* issue is fixed :) ... and I didn't want to mark the issue as 'patch (code need review)' since I couldn't prepare a proper patch.
Sorry if marking it as 'fixed' wasn't the correct thing to do, but the issue that I introduced by fiddling with the code appeared to be fixed by me continuing to fiddle with the code (since then I've broken some other stuff!), so it seemed best to flag the issue as resolved.