Copy a node's weight from the menu

Bartezz - December 5, 2008 - 17:51
Project:Weight
Version:5.x-1.x-dev
Component:Miscellaneous
Category:feature request
Priority:normal
Assigned:NancyDru
Status:closed
Description

Hi,

I'm doing some research and was wondering. I have some nodes which have links in the primary menu. These links in the menu are ordered by weight. Is it possible with this module to 'copy' that weight setting back into the node?

Reason for asking; the nodes in the menu are also being used in a view-block. And I would like them the have the same order as in the menu. This currently isn't possible with views (http://drupal.org/node/313140). So I was kinda hoping this module would help me with that issue :)

Cheers and have a good weekend!
Bartezz

#1

dreamlabs - December 9, 2008 - 13:01

Yeah this would be a great feature, saves lots of time when having lots of products in a menu.

#2

NancyDru - January 1, 2009 - 23:58
Assigned to:Anonymous» NancyDru
Status:active» postponed (maintainer needs more info)

Okay, doing this on node creation is pretty easy, but what about on update? Or is it that we should always use the menu weight and not allow the user to specify a node weight?

#3

NancyDru - January 2, 2009 - 00:32
Title:Copy a nodes wieght from the menu?» Copy a node's weight from the menu
Category:support request» feature request

I think I answered my own question.

What I am doing is that if you want this option (it will be a module setting), then it will override the regular weight setting. If you delete the menu item, the last weight that was inherited will remain.

#4

NancyDru - January 2, 2009 - 01:22
Status:postponed (maintainer needs more info)» fixed

Fix committed to both branches.

#5

Bartezz - January 5, 2009 - 13:18

Hey NancyDru,

Happy New Year :) Sorry for not replying earlier. Was on holiday for a couple of weeks. Anyway, thanx for this fix. I will update to the new module and let you know if there are any issues :)

Cheers

#6

dreamlabs - January 13, 2009 - 08:57

Wow great work! Thanks for this major improvement!

#7

NancyDru - January 14, 2009 - 01:04
Status:fixed» closed

#8

Bartezz - January 21, 2009 - 15:59

Hi Nancy,

Finally had some time to update to the new dev version. Here's what the results are;

- installed weight 1.x-dev jan 2009 on setup (fresh, without previous weight.module installation)
- admin/settings/weight checked 'use menu weight' and display on 'page' -> click update
- admin/settings/weight/setup -> 'x nodes need to be updated' -> click 'setup database'
- 'x nodes updated to support weight.module'

Not working??? Now when I go into edit mode of one of the nodes and check 'Node Weight' it's still 0. Eventhough it said it was updated?
Working!!! So I've set the 'node weight' manually for each node in node/1/edit, this works!
Working!!! Now when I go into node/1/edit and change Weight under 'Menu settings' it IS being adapted by weight.module
Not working??? When setting weights in admin/content/node these are NOT being stored, yet refreshing admin/content/node flags the nodes as 'updated'??? (EDIT: Using FF3)

If you need more information please let me know, happy to help make this dev version releasable :)

Cheers

#9

Bartezz - January 21, 2009 - 16:17

After reading; http://drupal.org/node/338090#comment-1211080

I checked and this is in the header;
Setting all the nodes to sticky doesn't resolve the issue!
Also, I'm not getting any javascript errors in webdevelopertoolbar in FF3.

So I started digging by calling admin/node/weight/_change_weight/1/-10 in the browser by hand... nothing happens....

So I looked at the function:

// ajax callback for weight manager page
function _change_weight($nid, $weight) {
  // Doing it this way preserves the revision information.
  $node = node_load($nid);

  _weight2encoded_sticky($node);

  node_save($node);
}

// Convert our weight to 'encoded' sticky value for DB.
function _weight2encoded_sticky(&$node) {
  if ($node->sticky) {
    $node->sticky = 100 - $node->node_weight;
  }
  // Unweighted non-sticky nodes will have a value of -100.
  else {
    $node->sticky = -($node->node_weight + 100);
  }
}

But i can't see where the weight parameter in _change_weight($nid, $weight) is actually being used???

Is there something missing here or am I missing it?

Cheers

#10

NancyDru - January 24, 2009 - 16:15
Status:closed» postponed (maintainer needs more info)

Hmm, after loading the node, we should set the weight as entered.

  $node->node_weight = $weight;

This seems to be okay in 5.x, and, indeed helps with 6.x. However, the admin/content/node display in 6.x shows the same weight for any nodes that were updated in this session. But, if I then filter some out, the display shows correctly. Weird!

#11

NancyDru - January 24, 2009 - 17:12

I committed that fix and it looks like it's working except possibly your second "not working." Please test this and confirm it.

#12

NancyDru - January 24, 2009 - 17:50
Status:postponed (maintainer needs more info)» fixed

Between this fix and #356335: Changing weight from contentpage doesn't work; throws httpRequest error, thsi should be fixed now.

#13

Bartezz - January 26, 2009 - 14:31

Hi Nancy,

The changes in 1.xdev (25 jan) work!

function _change_weight($nid, $weight) {
  // Doing it this way preserves the revision information.
  $node = node_load($nid);
  $node->node_weight = $weight;

  _weight2encoded_sticky($node);

  node_save($node);
}

// Convert our weight to 'encoded' sticky value for DB.
function _weight2encoded_sticky(&$node) {
  if ($node->sticky) {
    $node->sticky = 100 - $node->node_weigh       //### this line fixed it
  }
  // Unweighted non-sticky nodes will have a value of -100.
  else {
    $node->sticky = -($node->node_weight + 100);
  }
}

Thanx for the quick response!
Cheers

#14

NancyDru - January 26, 2009 - 14:43

Great. Thanks for the update.

#15

System Message - February 9, 2009 - 14:50
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.