First, let me say, DraggableViews is a lifesaver. Great work!
I'd like to add a custom handler for sorting, similar to the Flag Weights module, but I also want my handler to be aware of a Views argument and save distinct weights dependent on the value of the argument.
Use Case
- Content type "Tout" has a Title and a CCK Date field, which has From and To values
- View displays all Touts with Date as an argument.
- Tout A has Date From:May 20 To:May 25
- Tout B has Date From:May 21 To:May 22
- View with argument 2009-05-21 should display Tout B above Tout A
- View with argument 2009-05-22 should display Tout A about Tout B
I'm pretty sure I need to set up a database table that stores the node id, the view's argument value, and the weight.
The Question
I see that Flag Weights implements hook_draggableviews_handlers to save its weight info to the {flag_content} table. Is it also possible to alter the way a view loads within a draggableviews handler, or would I have to implement my own version of hook_views_pre_execute to make sure that I loaded the weight value that corresponded to the current argument?
Also, if anyone has a simpler idea to get the desired functionality, please chime in.
Thanks!
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | draggableviews-464870.patch | 1.09 KB | sevi |
| #6 | draggableviews_arg_ordering.patch | 6.8 KB | davideads |
Comments
Comment #1
sevi commentedGreat idea. This would solve #447656: Using filters on view changes order values
Why do you need this?
The value will be loaded by views. You simply have to implement a new Views field (see draggableviews.views.inc for an example).
Draggableviews passes the entire $view object to the handlers. You find the arguments at $view->args.
Is this what you expected to hear? :)
greetings,
sevi
Comment #2
Anonymous (not verified) commentedSorry, I'm new to handlers.
Example database table
I had the saving part down, but I couldn't figure out how implementing draggableviews_handler_modulename would ensure that the view would LOAD the correct data based on both NID and the ARGUMENT.
But it sounds like all I need to do is go back one more level and create an implementation of hook_views_plugins.
I'll follow-up on this thread as I build this. Thanks for the help!
Comment #3
sevi commentedYes, there's documentation for this missing :(
You need to implement
You can use additionally the "path" attribute. If not specified it will default to your module dir.
You have to implement you own field using
hook_views_data, which uses the query you specify.The fields specified by hook_views_data and the draggableviews-Handler are two different things.
You need to alter the query every time a view is beeing executed. Use the following hook:
you can add as many extra[] properties as needed. Look at draggableviews.views.inc for an example.
Or look at flag_weights module for an handler-example.
Comment #4
fearlsgroove commentedI've got a need for the same thing -- draggableviews handler that's unique by combination of views and arguments. Have you made any progress on this before I reinvent the wheel?
Comment #5
Anonymous (not verified) commentedNo actual coding yet. I'm relatively new to Drupal modules, so I tend to spend a good deal of time researching and planning the implementation before writing.
I've divided my coding plan into these chunks:
Questions:
Any other functionality that you would need for your use case, fearlsgroove?
Comment #6
davideads commentedWell, I wrote a patch that adds an args field expressed as a simple string -- it's a possible solution to this problem. I realized this issue was open after I wrote it. I've not tested it extensively, yet, but it seems to be working properly for an image gallery setup with a view path like galleries/gallery_nid/images/image_nid. I will test it with multiple arguments ASAP.
Comment #7
davideads commentedAlso, I realize there are uniqueness issues with the approach of the above patch.
Comment #8
fearlsgroove commentedSorry had to shelve this one for a while but it's still on the list for me.
@scmizer: no other requirements, just adding uniqueness per view + arguments would solve my problem.
RE: performance gains for arguments, one serialize/unserialize per load shouldn't have a significant performance hit i would think.
RE: clean, sure use nodeAPI and wipe any references that match the nid. see:
http://api.drupal.org/api/function/hook_nodeapi
@davideads: thanks for the patch! Haven't had a chance to look yet, but will in the next few days I hope.
Comment #9
davideads commented@fearisgroove: I should have a new version of the patch up in the next week or so, hopefully sooner -- I'm closing in on a satisfactory solution... I think.
Comment #10
sevi commentedMany thanks davideads :)
I looked at the patch and I would wonder if this could be improved any more :)
Works great.
I commited your changes to the DRUPAL-6--3 branch (http://drupal.org/cvs?commit=235300).
Greetings,
sevi
Comment #11
sevi commentedI enabled the "use arguments as well" option to try the new feature.
After disabling the option the view outputted duplicate nodes, because the args was not involved in the query.
I committed the attached patch.
Comment #12
davideads commentedThanks, Sevi -- I'm a little busy at the moment, but I'm really hoping to carve out time early next week to continue with my work on this. I think I have a better technique than the one used in that patch.
Comment #13
burningdog commentedThe 3.x-dev version works great with using arguments, thanks Sevi. davideads, if you change the technique that Sevi used in his patch and update the -dev code, will my custom ordering still be preserved when I update?
Comment #14
sevi commentedI'll end this discussion now.
@davideads: If you find some time to improve the current technique please create a new issue.
Greetings,
sevi
Comment #15
davideads commentedThanks, Sevi -- I should have some time to tackle it soon. Sorry about the delays. @Roger Saner: I'll ensure there's a proper upgrade path if at all possible.
Comment #17
charlie-s commented