Hi :)
Problem
If I have a set-up with :
- i18nmenu module
- DHTML Menu module
And I create a menu such that :
- Menu item M is set to 'All languages'
- Menu item M has sub-menus
- Menu item M has been localised using the translation interface into language L
Then:
- When viewing in the default language, the menu item M expands/collapses properly using DHTML
- When viewing in the language L, the menu item M causes a page reload when clicked on
Patch
Here is my attempt at understanding what is going on :
The problem is that by the time dhtml_menu_theme_menu_item is called, i18nmenu has already localised the terms. So it is not possible to use the title of the item to index the item (as done in _dhtml_menu_subtree).
This is a generic problem, and not just for i18nmenu -- any other module could also have modified the link's title/weight before it got to dhtml. So the patch I propose here (against 3.0 beta) uses only the mlid as index (hopefully that should never change !!!)
Index: dhtml_menu/dhtml_menu.module
===================================================================
--- dhtml_menu/dhtml_menu.module (revision 1296)
+++ dhtml_menu/dhtml_menu.module (working copy)
@@ -129,13 +129,14 @@
reset($stack);
$start = current($stack);
$tree = menu_tree_all_data($start['menu_name']);
+ // Create an index of mlid
+ $tree_index = array();
+ foreach ($tree as $key => $item) {
+ $tree_index[$item['link']['mlid']] = $key;
+ }
+
foreach ($stack as $item) {
- // Generate the sortable array key of an item:
- $path[] = (50000 + $item['weight']) .' '. $item['title'] .' '. $item['mlid'];
- }
-
- // Traverse the tree.
- foreach ($path as $key) {
+ $key = $tree_index[$item['mlid']];
if (!isset($tree[$key])) {
$tree = $tree[key($tree)]['below'];
if (!isset($tree[$key])) return array();
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | dhtml_menu_mlid_7-298720-12.patch | 3.17 KB | cburschka |
| #10 | dhtml_menu_63_mlid-298720-10.patch | 2.99 KB | cburschka |
| #6 | dhtml_menu_63_mlid-298720-6.patch | 2.74 KB | cburschka |
| #4 | dhtml_mlid_patch.txt | 831 bytes | Alice Heaton |
Comments
Comment #1
cburschkaI've tried to work with mlid before, specifically when assigning unique ID attributes to links, and for some reason it turned out that not all items had an mlid set.
I'll check again, and if I find I can rely on the mlid, this would be a good change.
Meanwhile, please upload your patch as a file.
Comment #2
cburschkaSorry, your fix breaks book navigation - for some reason the mlids of the book menu items are not included in the tree index that you build, meaning that book navigation items can't expand dynamically. You'll need to find some workaround for that...
Comment #3
cburschkaI can narrow down the problem: It specifically occurs when you are inside the book navigation menu. If you are anywhere else, the complete menu will load dynamically, but if you are inside it, only the active path will be loaded.
Comment #4
Alice Heaton commentedHere is the patch as a file. I am confused about the mlid thing - if that is not guaranteed, it means there is no way to identify a menu item ? I'll have a look when I can ;)
Comment #5
cburschkaThat is exactly what I found, and it is the reason I am using that silly "50000 + weight, title" index in the first place - that is what the menu tree generator seems to use for unique keys internally.
I may have found the problem: They have mlids, but they don't have a menu name set for some odd reason.
Comment #6
cburschkaHa, sorry, your approach is actually correct; all items except for tabs like node/%nid/edit have mlids and menu_names; my earlier problem has nothing to do with this.
Your implementation was merely incomplete. You are indexing the top level of the tree, but you need to use a recursive function to index the whole tree.
Patch is here.
Comment #7
cburschkaThis can probably go in. I suggest you test it again to make sure it works with the i18nmenu module now.
Comment #8
Alice Heaton commentedHi Arancaytar - thanks for your work ! I haven't had time to test your new patch yet, but will do so today or tomorrow ! Thank you so much for this !
Comment #9
cburschkaPatch borked.
Comment #10
cburschkaTesting this.
Comment #11
cburschkaCommitted to DRUPAL-6--3. Still needs porting to D7.
Comment #12
cburschkaHere we go.
Comment #13
cburschkaCommitted to HEAD after some testing.
Comment #14
Alice Heaton commentedA bit late, but I can confirm this patch works :) Thanks !