Don't know if this is a DHTML menu or Treemenu related bug, but here goes.

I have a Taxonomy Treemenu on which I have enabled the DHTML menus module.

It works just fine, except for one thing. When I click a node and go to the corresponding
page the DHTML menu is collapsed to its initial state which is rather annoying.

This is with DHTML Menu version 6.x-3.5.

Anyone else experiencing this problem?

Comments

rcrowther’s picture

Status: Active » Postponed

Basicly - yes! I know! One of my sites works like this.

DHTML Menu version 6.x-3.5 is a shady affair, a radical revision of their approach which had a drastic effect on Treemenu's handling. Treemenu needed a complete re-write to support it. I saw I would need to do some module poking to support this feature, and just didn't have the time to walk that diversion.

If this is an immediate concern, I can't support it. I have a sort of need to know that DHTML Menu is not going to shift their base underneath me, particularly with Drupal 7 imminent. But supporting DHTML Menu is a stated and primary concern of this module, so you can be assured that I will get there, sooner or later.

If someone wants to dive in and figure out how DHTML expands, so how we can pass the data back in, please do!

Probably not the answer you were hoping for, but hopefully lets you consider your strategy with some information on hand.

Rob

joerichsen’s picture

Thank you for your honest reply to my report :-)

I'm a developer myself, so if you give me some pointers on where to look in the code, maybe I could help resolve this problem?

/Jørgen

joerichsen’s picture

Dived into the DHTML menu code and the

function dhtml_menu_theme_menu_item($link, $has_children, $menu = '', $in_active_trail = FALSE, $extra_class = NULL) {

has the code

  if ($menu && !($in_active_trail || in_array(substr($item['options']['attributes']['id'], 5), $cookie))) {
    $extra_class .= ' collapsed start-collapsed ';
  }

which cause the menu to collapse when a new page is loaded. Further inspection shows the $in_active_trail variable is never true? Is the $in_active_trail a variable passed by Taxonomy Tree Menu?

rcrowther’s picture

At present TTM passes nothing back to DHTML Menu! It feeds a complete tree (like menu_all_data) to the screen, to let DHML Menu work its now sophisticated magic.

I recall, though I've never gone into it, that DHTML Menu uses the cookie to recall the current state of data.

Programming questions become - what is that variable? If we know where the tree is going (from the cookie), why do we need to know anything more about the trail? And where is the variable sourced?

And how about just hacking the variable true, to see what will happen?

Sorry my replies are slow - I have external concerns right now...

Rob

joerichsen’s picture

OK, I will try to explain what I see.

I have a taxonomy that looks like this

# Product1
    * Subcategory
# Product2

And with nodes and it looks like this

# Product1
    * Subcategory
          o Super product 1
# Product2
   o Super product 2

If I look at the HTML in Firebug when the tree has manually been fully expanded it looks like this

<li class="first dhtml-menu start-collapsed expanded">
  <a id="dhtml_menu-126" href="/~joe/drupal-6.14/?q=taxonomy/term/1">Product1</a>
  <ul class="menu" style="display: block;">
    <li class="last dhtml-menu expanded"> 
    <a id="dhtml_menu-128" href="/~joe/drupal-6.14/?q=taxonomy/term/3">Subcategory</a>
      <ul class="menu" style="display: block;"></ul>
    </li>
  </ul>
</li>
<li class="last dhtml-menu start-collapsed expanded">
  <a id="dhtml_menu-127" href="/~joe/drupal-6.14/?q=taxonomy/term/2">Product2</a>
...

And the dhtml_menu cookie value is _menu-126,_menu-128,_menu-127.

When I click "Super Product 1" it displays the page for "Super Product 1" and the menu is collapsed.

The cookie still has the same values but the html looks like this

<li class="first dhtml-menu collapsed start-collapsed ">
  <a id="dhtml_menu-126" href="/~joe/drupal-6.14/?q=taxonomy/term/1">Product1</a>
  <ul class="menu" style="display: block;">
    <li class="expanded last dhtml-menu ">
      <a id="dhtml_menu-128" href="/~joe/drupal-6.14/?q=taxonomy/term/3">Subcategory</a>
...

ie. the outermost menu item is collapsed and not expanded. One thing to note is that the "Subcategory" is in fact correctly expanded - but it is hidden by the collapsed "Product1" parent.

Why the outermost menu item is collapsed and the sub menu items seem to be expanded correctly is beyond me so any help is really appreciated :-)

Btw. wrt. your previous comment, if I set $in_active_trail to true it expands the whole tree all the time.

/Jørgen

joerichsen’s picture

Hmm, now I have a working hack. DHTML menus seem to have some sort of stack for the menus and if I comment out the line

if (isset($link['menu_name']) && isset($link['mlid'])) {

if the function dhtml_menu_theme_menu_item_link
in dhtml_menu.module it seems to work.

Further inspection shows that I have the "Show nodes" setting enabled, Treemenu will create menu items with an empty menu name, hence not pushing it onto the DHTML menu stack, but it will happily try to pop them from the stack, get a NULL value and this will eventually lead to the collapsed outermost menu level.

I don't know if what I just wrote makes any sense to anybody else but me, but feel free to ask questions :-)

/Jørgen

joerichsen’s picture

Another way to fix this problem is to add

    $node_element['menu_name'] = $mlid;

to line 3076 in taxonomy_treemenu.module right after

$node_element['mlid'] = $mlid;

/Jørgen

rcrowther’s picture

You've got my attention alright! I would have love to turn Firebug loose on DHTML Menu, but I did see the stacking and so forth, which is why I backed off at the point I did. I had the new works-with-any-module menu routing to build.

Do you think this is a solid fix? Admit I don't understand it yet, or ramifications. "Treemenu will create menu items with an empty menu name" sounds like it could use a fix anyhow?

Rob

joerichsen’s picture

I am by no means an expert in Drupal's menu system but I think that adding a menu_name attribute to the node menu items should do no harm. And it fixes the problem so I'm happy :-)

The comment

    // These items are the crutial ones when it comes to rendering.
    //   (the others are relevant only to
    //      menu organisation/customisation, which doesn't really much affect us)

just before the line I added, seems to suggest that adding menu_name could be useful.

/Jørgen

rcrowther’s picture

Hi joerichsen,

Being an expert is no substitute for being thoughtful, and contributions, in my book!

Especially as you've done some work, I'd just like to explain why work on Treemenu is near impossible for me right now.

My flatmate and friend recently suffered a total physical collapse (in another country). She's been hospitalized, and apart from being troubled about her health, this means I am very close to loosing the flat, which would make me homeless.

Hope you don't mind the personal note.

So, I'm sure you'd like this tomorrow, but given my situation, would it be ok if we delay for a while? I can't say how long, but if you have some time, I'd appreciate it.

Rob

joerichsen’s picture

Sorry about you friend :-(

I have patched my local copy of Treemenu and it works fine, so I'm not in a hurry.

Hope your friend gets better (and that you don't loose the flat).

Take care.

/Jørgen

fschaff’s picture

Hi, I have the same problem
So I tried the #7 fix but it doesn't fix it.
No change

Is there something else to do ?

Thanks

fschaff’s picture

Please, I really need your help
Have you got a fix ?
Thanks!

joerichsen’s picture

I have received a number of requests for my patched version.

It is based on 6.x-7.1 and can be downloaded here:
http://www.erichsen.net/taxonomy_treemenu.zip

/Jørgen

rcrowther’s picture

First, thankyou /Jørgen for making stuff available. Good work.

I've only just gained the internet again, and it's a bad connection. I've lost the Windows computer I shared for testing. The much regretted switch of ISP has left my development environments in disarray. Due to a Drupal security alert I havn't even re-established connection to my own cvs account (if you know what I'm talking about). The operating system me and my friend have left is Ubuntu, which we use as LTS, and is due for upgrade, so both of us have a massive amount of work to salvage and backup nearly three years of projects (far more than just TTM).

This is some of the background as to why /Jørgen's patch will not be committed soon - I can't test, let alone upload.

However, I have faith in /Jørgen's solution, we were talking about it when the real world came to get me, and I recommend anyone who would like this fix to try the download.

Rob

amin.nasiri’s picture

Thanks for providing this fix. After adding this, all terms are always expanded, and there is no way to collapse them. I have a long menu and this is kinda annoying. Is this how the fix works? expands all items all the time? Or am I doing something wrong?

thanks a lot!

kiril-daedalus’s picture

unfortunatly, no change for me with this patch, the node link has the "active" class but the menu is still collapsed :(

any ideas ?

bekirdag’s picture

Drupal checks {menu_links} table to check if current page's path related with another. And in_active_trail returns true.

But drupal does not adds menu trails for terms of a node, so the menu shows collapsed in the node page.

Solution:
http://drupal.org/project/taxonomy_menu_trails

This module adds that trails for "taxonomy menu module". Works like a charm.

tedcamaro’s picture

I haven't had any luck with Taxonomy Menu Trails keeping my DHTML enabled Taxonomy Treemenu from collapsing when you click through to a node. Can you clarify whether or not you were using DHTML Menu and whether any customization or specific Taxonomy Menu Trails menu options that you found were successful?

Thanks