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

Comments

ericclaeren’s picture

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

NancyDru’s picture

Assigned: Unassigned » 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?

NancyDru’s picture

Title: Copy a nodes wieght from the menu? » Copy a node's weight from the menu
Category: support » feature

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.

NancyDru’s picture

Status: Postponed (maintainer needs more info) » Fixed

Fix committed to both branches.

Bartezz’s picture

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

ericclaeren’s picture

Wow great work! Thanks for this major improvement!

NancyDru’s picture

Status: Fixed » Closed (fixed)
Bartezz’s picture

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

Bartezz’s picture

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

NancyDru’s picture

Status: Closed (fixed) » 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!

NancyDru’s picture

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

NancyDru’s picture

Status: Postponed (maintainer needs more info) » Fixed
Bartezz’s picture

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

NancyDru’s picture

Great. Thanks for the update.

Status: Fixed » Closed (fixed)

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