Jump to:
| Project: | Weight |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (works as designed) |
Issue Summary
I am running Drupal 6.x (tag DRUPAL-6) with the most recent tags of views and weights (tag DRUPAL-6--1). Everything is up-to-date.
I set up a view to do reordering of particular nodes (matching a filter) of a particular content type ('blog_items'). I followed the directions in the README. I set the sort order of the page view to 'weight, descending' as per the instructions.
However, when I bring up the view, reorder the items, and save the results, it always reverses the order of my desired intent.
I have tried sorting the view by weight both ascending and descending but it seems to make no differnce. If I make a change and save, the page refreshes with the order reversed of what I had set it to.
I'm not sure if this is a bug or a misconfiguration on my part; but I couldn't imagine what I could try differently.
$view = new view;
$view->name = 'practice_areas_reorder_pages';
$view->description = 'Pages that use weight module to reorder the posts on the practices areas pages';
$view->tag = 'blog';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
'title' => array(
'label' => '',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'link_to_node' => 1,
'exclude' => 0,
'id' => 'title',
'table' => 'node',
'field' => 'title',
'relationship' => 'none',
),
'weight' => array(
'label' => 'Weight',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'empty' => '',
'hide_empty' => 0,
'empty_zero' => 0,
'set_precision' => FALSE,
'precision' => 0,
'decimal' => '.',
'separator' => ',',
'prefix' => '',
'suffix' => '',
'exclude' => 0,
'id' => 'weight',
'table' => 'node_weight',
'field' => 'weight',
'relationship' => 'none',
),
));
$handler->override_option('sorts', array(
'weight' => array(
'order' => 'ASC',
'id' => 'weight',
'table' => 'node_weight',
'field' => 'weight',
'relationship' => 'none',
),
));
$handler->override_option('filters', array(
'status_extra' => array(
'operator' => '=',
'value' => '',
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'status_extra',
'table' => 'node',
'field' => 'status_extra',
'relationship' => 'none',
),
'type' => array(
'operator' => 'in',
'value' => array(
'blog_item' => 'blog_item',
),
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'type',
'table' => 'node',
'field' => 'type',
'relationship' => 'none',
),
));
$handler->override_option('access', array(
'type' => 'role',
'role' => array(
'3' => 3,
'6' => 6,
),
));
$handler->override_option('cache', array(
'type' => 'none',
));
$handler->override_option('use_ajax', TRUE);
$handler->override_option('items_per_page', 0);
$handler->override_option('use_pager', '0');
$handler->override_option('style_plugin', 'weight');
$handler->override_option('style_options', array(
'grouping' => '',
'override' => 1,
'sticky' => 0,
'order' => 'asc',
'columns' => array(
'title' => 'title',
'weight' => 'weight',
),
'info' => array(
'title' => array(
'sortable' => 1,
'separator' => '',
),
'weight' => array(
'sortable' => 1,
'separator' => '',
),
),
'default' => 'weight',
));
$handler->override_option('row_options', array(
'inline' => array(
'title' => 'title',
'created' => 'created',
),
'separator' => '-',
));
$handler = $view->new_display('page', 'Cyclists reorder', 'page_1');
$handler->override_option('filters', array(
'status_extra' => array(
'operator' => '=',
'value' => '',
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'status_extra',
'table' => 'node',
'field' => 'status_extra',
'relationship' => 'none',
),
'type' => array(
'operator' => 'in',
'value' => array(
'blog_item' => 'blog_item',
),
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'type',
'table' => 'node',
'field' => 'type',
'relationship' => 'none',
),
'tid' => array(
'operator' => 'or',
'value' => array(
'336' => '336',
),
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'type' => 'select',
'limit' => TRUE,
'vid' => '8',
'id' => 'tid',
'table' => 'term_node',
'field' => 'tid',
'hierarchy' => 0,
'override' => array(
'button' => 'Use default',
),
'relationship' => 'none',
'reduce_duplicates' => 0,
),
));
$handler->override_option('path', 'practice/cyclists/reorder');
$handler->override_option('menu', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
'name' => 'navigation',
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
));
Comments
#1
I'm seeing the same behaviour -- if I just submit the form without making any changes, the order stays the same, however if I drag any of the nodes up or down then hit submit, the nodes appear in exactly the reverse order from what they should be. The only way to fix it is to drag items around again, then submit and the nodes are reversed again (i.e., returned to their original position).
#2
Some more information: it looks like this is happening in weight.views.inc in the function weight_view_weight_form_submit, specifically these lines:
<?phpif ($node->sticky) {
$node->sticky = (-1 * $weight) + 100;
}
// Unweighted non-sticky nodes will have a value of -100.
else {
$node->sticky = (-1 * $weight) - 100;
}
?>
I don't really understand why the weight is being manipulated that way on submit. If I comment out the block above and just say:
<?php$node->sticky = $weight;
?>
. . . everything seems to work properly, and nodes are reordered properly rather than reversed.
What am I missing?
#3
My proposed solution above doesn't work -- the module is doing the same +/- 100 thing in a number of places, and I think I see now why it's necessary.
Here's another shot at a fix, referring to the same block of code:
<?phpif ($node->sticky) {
$node->sticky = (-1 * $weight) + 100;
}
// Unweighted non-sticky nodes will have a value of -100.
else {
$node->sticky = (-1 * $weight) - 100;
}
?>
Say there's a weight set and it's -50 -- the first part of this condition will do:
(-1 * -50) + 100
Which equals 150. I don't think that's right -- even after being inverted for the sticky column, shouldn't the number fall into the same range as the uninverted number? I've changed this to:
<?phpif ($node->sticky) {
if ($weight < 0) $node->sticky = $weight + 100;
elseif ($weight == 0) $node->sticky = 0;
else $node->sticky = $weight - 100;
}
// Unweighted non-sticky nodes will have a value of -100.
else {
$node->sticky = (-1 * $weight) - 100;
}
?>
...it seems to be working now. I'd be happy for some feedback on this from someone with a better understanding of how the inversion is working, though.
#4
I think your issue is in the Weight Changer style settings. The default sort should be set to None. Changing that setting in the exported view produced the expected behavior.