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!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

NancyDru’s picture

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.

chasz’s picture

erhmm, CCK will get you into views

libeco’s picture

I don't really understand what you mean. Can I sort by weight through cck and views?

NancyDru’s picture

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é.

libeco’s picture

Sorry, I was referring to chasz' comment. I tried weight in views and didn't really get it to work in D6.

Jody Lynn’s picture

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.

NancyDru’s picture

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.

Jody Lynn’s picture

Status: Active » Needs review
FileSize
9.14 KB
3.64 KB

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.)

NancyDru’s picture

Wow, thanks, Jody! This is fabulous. I don't suppose you also have a patch that increases the number of hours in a day?

lyricnz’s picture

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).

mitchell’s picture

Could you please post screenshots?

chasz’s picture

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

gdd’s picture

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.

gdd’s picture

Status: Needs review » Needs work

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.

populist’s picture

Status: Needs work » Needs review
FileSize
12.95 KB

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).

Jody Lynn’s picture

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

NancyDru’s picture

Thanks for the patches. I'm back from vacation, so as soon as I find my brain again, I'll test them.

pfournier’s picture

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

virtualdrupal’s picture

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...

Jody Lynn’s picture

FileSize
13.19 KB

Here's a rerolled patch to correct the patch problem reported in #19 and add the filter from #18.

NancyDru’s picture

NancyDru’s picture

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.)

NancyDru’s picture

Status: Needs review » Needs work

It has been committed, so an incremental patch would be needed.

Jody Lynn’s picture

Status: Needs work » Needs review
FileSize
658 bytes

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':

function weight_views_handlers() {
  return array(
    'info' => array(
      'path' => drupal_get_path('module', 'weight'),
     ),

(patch attached)

NancyDru’s picture

Status: Needs review » Fixed

Thanks, that did the trick.

SofiaSund’s picture

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

Jody Lynn’s picture

Version: 6.x-1.0-beta1 » master
Status: Fixed » Needs review
FileSize
5.98 KB

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.

SofiaSund’s picture

Version: master » 6.x-1.0-beta1
Status: Needs review » Fixed

Thanks a million!

NancyDru’s picture

Version: 6.x-1.0-beta1 » master
Status: Fixed » Needs review

Resetting status.

tanc’s picture

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!

sheise’s picture

FileSize
5.99 KB

I have rerolled the patch in comment #27 for HEAD.

NancyDru’s picture

Status: Needs review » Fixed

Committed.

Status: Fixed » Closed (fixed)

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

giginos’s picture

Note: Activateing the "Weight" ist quite hidden. You can activate the "Weight" in the Tabs of the Content types.

Link: /admin/structure/types/manage/article