Posted by libeco on September 27, 2008 at 4:07pm
| Project: | Weight |
| Version: | master |
| Component: | Miscellaneous |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
Issue Summary
Hi again,
Could the weight module somehow be used with views?
I tried sorting by stickiness on a new view, but nothing happened.
Thanks in advance!
Comments
#1
Due to the massive changes in Views, it may be a while before I can figure out what to do. If someone wants to submit a patch, I would be very happy.
#2
erhmm, CCK will get you into views
#3
I don't really understand what you mean. Can I sort by weight through cck and views?
#4
The weight is part of the sticky field and it may work correctly with Views2; I just have not had enough time to find out. In 5.x, special Views code had to be added to make it work correctly and I have not had the time yet to try to rework the Views code, which is not my forté.
#5
Sorry, I was referring to chasz' comment. I tried weight in views and didn't really get it to work in D6.
#6
Sorting by stickiness seems to be working for me with Views 2, however it is necessary to make the sort order DESC rather than ASC to get the desired ordering.
#7
Sticky should be descending. Unencoded sticky is 1 and unencoded non-sticky is 0, so you would want the 1's first.
I'm glad it's working. It does sound like perhaps an issue against Views might be in order though.
#8
I created a views integration for the module. It includes a Weight field which displays the weight, a Weight sort (which allows you to order by Weight ASC which I think is more intuitive but is the same as ordering by Sticky DESC), and best of all a new style plugin called 'Weight Changer'.
The idea is that you can set up a view using the 'Weight Changer' style and include the Weight field and Sort by Weight ASC. The resulting view is a form displayed as a table with drag and drop for updating the weights. This is working for me so far in my testing.
I'm attaching a patch with changes to weight.views.inc and weight.module and a zip file which contains additional files (handlers for views and a template file for the style plugin.)
#9
Wow, thanks, Jody! This is fabulous. I don't suppose you also have a patch that increases the number of hours in a day?
#10
Have you looked at http://drupal.org/project/draggableviews? This can already be used to reorder records based on a CCK field (or non-CCK if they extend it http://drupal.org/node/317400).
#11
Could you please post screenshots?
#12
they have a demo over there.
if you want weight in views....then just create a normal numerals dropdown CCK field and and use the views to order it by ASC or DESC
this is for people who dont use views or waiting for views to mature a bit
#13
I got this running today, it was just what I needed for a client project. One thing I noticed is that the draggable view does not appear in Views' preview area. Is this by-design, a bug, or user error? It confused me for a good while since I thought that I had screwed something up in my View.
I also tried draggable views and never got it to work.
#14
I did find one problem. In weight-view-weight-form.tpl.php, line 15 throws a notice on every instance of $row, because it tries to look up 'nid_hidden' in $fields and it doesn't exist. This file is in the zip, so I don't really know how to patch it, but you should replace line 15 with
<td class="views-field views-field-<?php print isset($fields[$field]) ? $fields[$field] : '' ?>">To get around the problem.
#15
this patch is flat cap awesome.
rerolled as a single file using some cvs voodoo, the php notice talked about in #14 is resolved, and i moved the drupal_add_tabledrag() callback to the _form() function instead of the template (so people can override as needed).
#16
I moved the hook_theme into weight.module rather than weight.views.inc because I think having it in the inc was causing some problems related to theme registry (could be involved in the #13 issue.)
Also added a little to populist's help text
#17
Thanks for the patches. I'm back from vacation, so as soon as I find my brain again, I'll test them.
#18
Could you add the following code in weight_views_data() (file weight.views.inc), at the end of $data['node']['weight']
'filter' => array('handler' => 'views_handler_filter_numeric',
'label' => t('Weight'),
),
This would enable filtering by weight.
(I am too lazy to resubmit the whole patch)
Thanks
#19
I just wanted to chime in that I ran the patch from past #16 and was not given the option to sort by weight in views 2, it DID seem to fail on the very last line of the patch with patch: **** malformed patch at line 424:.
Refreshing cache and rescanning templates didn't help. So I started fresh and tried to patch using the files in post #8 and now 'sort by weight' is an option and everything works great.
Thanks for the patches by the way, this module is exactly what I needed...
#20
Here's a rerolled patch to correct the patch problem reported in #19 and add the filter from #18.
#21
Marked #319479: i can't make it run on my views as duplicate.
#22
Patch failed on line 339.
I manually created the new files and removed them from that patch and it applied.
However, I get "Error: handler for node_weight > weight doesn't exist!" (Yes, I cleared the Views cache.)
#23
It has been committed, so an incremental patch would be needed.
#24
It's because the handlers were previously in a separate handlers subdirectory. If you don't want to have that subdirectory then just change the path in this function as so to not include 'handlers':
<?phpfunction weight_views_handlers() {
return array(
'info' => array(
'path' => drupal_get_path('module', 'weight'),
),
?>
(patch attached)
#25
Thanks, that did the trick.
#26
Hi thanks for this patch! It mostly works well on my test site, but every now and then when I make changes or move between pages I get the following warning messages and my weight-view disappears:
* warning: Invalid argument supplied for foreach() in /path/to/sites/all/modules/weight/weight-view-weight-form.tpl.php on line 4.* warning: Invalid argument supplied for foreach() in /path/to/sites/all/modules/weight/weight-view-weight-form.tpl.php on line 12.
On my current installation I'm using a page view which works fine, but the warning messages show up as soon as I enable SimpleMenu and disappear as soon as I disable it.
On a previous installation, it seemed to be more random - the same block view was showing correctly on some pages but gave me the warning messages on others.
I'm rather new to Drupal and I don't really know where to start looking. Does anybody know what the problem could be and what could be a possible solution?
Thanks, Sofia
#27
A couple of tweaks to fix SofiaSund's issue, and I also moved the template_process function into weight.module as it was not always loading for me from within the views.inc.
Note this is now a patch on HEAD.
#28
Thanks a million!
#29
Resetting status.
#30
This is great, thanks for writing the patch Jody. It appears to work very nicely in all regards in my testing so far. The only thing that seems to need some attention is the views templates.
Currently if you look at 'Theme: information' in Views 2 you'll notice that an expected template file is missing: weight-view-weight.tpl.php (File not found, in folder sites/all/modules/weight/). From what I can tell this file is needed if a themer wants to override a table row in their theme folder.
Any chance you can abstract the necessary data from weight-view-weight-form.tpl.php into a weight-view-weight.tpl.php file? Without this I'm not sure how to theme my table rows.
Thanks!
#31
I have rerolled the patch in comment #27 for HEAD.
#32
Committed.
#33
Automatically closed -- issue fixed for two weeks with no activity.