Menu items created by taxonomy_menu, even when set to "Expanded" still don't show as expanded in the frontend. This is caused by taxonomy_menu messing up the "has_children" column in the menu_links table for menu items it maintains. Specifically, when _taxonomy_menu_nodeapi_helper() is run via a hook_node.

How to recreate the error:

1. Create a new taxonomy term so it appears in the menu (you may need to assign nodes to the term because blank terms don't render in the menu). Do not modify the taxonomy menu link, let the system create it, don't drag items in/out of it, or move it around.

2. Create a new node or edit an existing one, and using the node form, select your newly created taxonomy menu item (which was produced by taxonomy_menu).

3. Visit the frontend and notice that even though "expanded" is checked on your taxonomy menu item, that branch of the tree is not expanded.

This has to do with the fact that even though our taxonomy menu item has a child, the "has_children" row in the database has not been updated.

I think this has to do with the fact that a taxonomy menu item is re-created on node_update, and since it didn't have children before the node was saved, the newly updated/created item after node update also thinks it doesn't have children. When has_children is set to 0 in the database, drupal will not render the menu as expanded even when expanded is set to 1.

I worked around this in my installation by modfying taxonomy_menu.module around line 477, but I doubt this is the best method because I don't understand the totality of the module.

 //If the menu item already existed, no need to recreate it.	
      $previous_item = menu_link_load($args['mlid']);
      if(!$previous_item){taxonomy_menu_handler($op, $args, $node);}

This is a pretty aggravating bug, please let me know if anyone requires more details, as I'd love to help get it resolved.

Thanks!

Comments

farse’s picture

i have this issue as well. tried both assigning the content node to the taxonomy link and also assiging the taxonomy link to the content node link. neither worked. your fix didn't seem to work either. hmm...

menu works fine though if i do neither of these.

farse’s picture

dinhtrung’s picture

I have a simple patch for this issue:

diff -r 3284d31adce0 sites/all/modules/taxonomy_menu/taxonomy_menu.module
--- a/sites/all/modules/taxonomy_menu/taxonomy_menu.module	Mon Jul 16 10:28:55 2012 +0700
+++ b/sites/all/modules/taxonomy_menu/taxonomy_menu.module	Mon Jul 16 10:29:00 2012 +0700
@@ -609,7 +609,10 @@
     $children = taxonomy_get_children($item['tid']);
     if (!empty($children)) {
       $link['has_children'] = 1;
-    }
+    } elseif (! $insert) {
+		$menu_link = menu_link_load($link['mlid']);
+		$link['has_children'] = $menu_link['has_children'];
+	}
   }
 
   // If remove is true then set hidden to 1

If you attach your node to a sub-menu item of the taxonomy menu, its parent will be displayed as expanded.

hles’s picture

Priority: Critical » Normal

Hardly critical.

johnv’s picture

Title: Expanded Behavior not working properly due to has_children not being set in menu_links table via hook_node_update » 'Auto expand menu items' does not work: menu_links property 'has_children' is not set via hook_node_update()

Working through the issue queue: more explicite title.
(keywords: hide, hidden, hiding)

Primajin’s picture

Version: 7.x-1.x-dev » 7.x-1.5

This issue is still a problem in 7.x-1.5.
dinhtrung's patch sadly doesn't work for me. The only workaround I found so far is checking "Flatten the taxonomy's hierarchy in the menu". That way the hierarchy get's lost but at least i can see the subnavigation points again.

Please fix this

TannerLavoie’s picture

This is still an issue in 7.x-1.5 and dinhrung's patch isn't working for me either. Has anyone found a solution to this?

vladimiraus’s picture

Status: Active » Closed (outdated)

Thank you for your contributions.
Drupal 7 is no longer supported.
Closing this issue as outdated.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.