Weight (suddenly) being ignored
| Project: | Submenu Tree |
| Version: | 6.x-1.3 |
| Component: | User interface |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
| Issue tags: | weight |
Jump to:
I'm using Submenu Tree to display the parent menu (as menus) before content, so I set weight = 0 on the node form and it worked as expected. The module was working perfectly on my site, but suddenly I created a node in which the module misteriously showed the menu after the content.
I just thought that I had forgot to set "weight = 0", but that's was not the case. Even if I put weight to the minimum value (-10), the menu is always being shown after the content.
I did a few tests, and discovered that if I also enable "Enable siblingmenu trees for this node" them the (parent) submenu tree is shown before content as expected (though the sibling menu is being shown after content, even if I use weight = 0 for the sibling).
I'm scratching my head for an hour or so and found no solution. There already are dozens of nodes on the site where the menu is being shown on the right place. There's nothing particular about this new node -- it's just a plain "page" node.
Did anybody have seem this already? Any clues?

#1
Nope, haven't seen it :)
But you can answer some questions for me and help me diagnose.
Does this only affect one page node, or all page nodes?
Are you using CCK and CCK fields in your page nodes?
Are you using any other modules which may affect the way a node is displayed?
Are you using a custom template for your page nodes? ie. a node-page.tpl.php in your theme?
#2
The module behaved as expected in half-dozen nodes.
Then suddenly for one node it didn't show the menu on the right location. All other nodes still ok.
I've just created a new node/menu structure just to check -- the menu is still not being shown on the correct location on new nodes. *sigh*
No. Just plain title/body fields.
Well... let's see... Menu Settings per Content Type maybe? Or perhaps Local Menu?
These are the only two node/menu related modules on my install (apart CCK, various CCK custom fields, Views, and another bunch of unrelated modules).
No.
-x-x-
If you need more help to solve this issue, let me know. Since the site is not in production yet, I'm willing to change the module and add debug code (I have some experience in PHP programming) to help us figure what heck is going on.
#3
As a quick test, do you want to just disable Menu Settings per Content Type and Local Menu and see if it affects the issue? It shouldn't, but stranger things have happened.
Otherwise, yes, maybe some debug code is in order.
Or would you be willing to give me a database dump of your site? Then I can try to recreate on my own system.
#4
I have observed that the siblingmenutree_weight is an UNSIGNED integer, which means values less than 0 will not save when saving/updating a node:
siblingmenutree_weight int(10) UNSIGNED
In the module,
function submenutree_schema() {$schema['node_submenutree'] = array(
'description' => t('The base table for submenutree'),
'fields' => array(
'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'),
'submenutree_enable' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'),
'submenutree_title' => array('type' => 'varchar', 'length' => '255', 'not null' => TRUE, 'default' => ''),
'submenutree_display' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'),
'submenutree_weight' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'),
'siblingmenutree_enable' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'),
'siblingmenutree_title' => array('type' => 'varchar', 'length' => '255', 'not null' => TRUE, 'default' => ''),
'siblingmenutree_display' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'),
<b> 'siblingmenutree_weight' => array('type' => 'int', 'unsigned' => TRUE</b>, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10')),
'primary key' => array('nid'),
);
return $schema;
}
The weight column is in fact UNSIGNED. This appears to be a bug. Can anyone confirm?
#5
It looks like the bug is related to this unsigned issue.
Today I spent some time debugging the problem. By default, the 'body' content in the $node structure has an weight 0. Since the minimum 'submenutree' weight is 0 (due to the unsigned bug), the sorting of contents that are done inside Drupal to render node body may be just not touching the two items when sorting.
If I manually set
$weight = -1in the_submenutree_menutree_view()function just for testing, then all sub menu trees get rendered before the body.What remains unexplained is why in some nodes the 'submenutree' content is being rendered before 'body', even thought both have 'weight = 0'.
#6
Confirmed.
After
alter table node_submenutree modify column submenutree_weight integer default 0I'm now able to set weight < 0. Just setting weight to -1 makes the submenutree always appear before node body.#7
Hi guys,
Confirmed, tested, and committed.
Thanks for chasing this up and solving it for me.
Makes my job that much easier :)
There should be a new 6.x-1.4 release in a few minutes time with this fix.
(Note: This fix hasn't been backported to the 5.x branch. The 5.x branch is soooo old :)
Thank you.
#8
bengtan, it would be good if you explain clearly on the documentation (and/or field description) that by default the node body has a weight of 0, so if one also set the menu parent/siblings weight to 0, then the results are unspecified.
Perhaps removing the 0 weight altogether is even a better solution -- if ones wants the menu after the body, one sets weight = 1, otherwise -1 is the correct choice.
#9
It's a little bit more tricky than that.
When submenutree was initially written (for Drupal 5.x), your observation was mostly true ie. the node body weight had a default weight of 0.
However, with Drupal 6.x, there is at least one commonly used module (CCK) which fiddles around with the body weight and can make it any value.
So, the idea of manually assigning a weight via a select dropdown in the submenutree fieldset is a bit outdated, naive and, depending on what other modules are also in use, somewhat broken now :(
The ideal fix would be to assign weights using some other mechanism .... An issue for another day, I guess, or when submenutree eventually moves to Drupal 7.x.
#10
Hmmm... what if we position the submenu tree relatively to the body? Something like this (pseudo-code):
<?php
$body_weight = $node->content['body']['#weight'];
if ( $menu_position == 'before-body' )
$weight = $body_weight - 1;
else
$weight = $body_weight + 1;
$node->content['submenu_tree']['#weight'] = $weight;
?>
#11
Automatically closed -- issue fixed for 2 weeks with no activity.