Integrate with views
attiks - July 30, 2008 - 15:15
| Project: | Fasttoggle |
| Version: | 6.x-1.3 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
| Issue tags: | views |
Description
Is it possible to use the same links as views columns and if so did anyone already created a patch for it?
Cheers
Peter

#1
Fasttoggle actually has integration with views, but the APIs probably changed with Views2 for Drupal 6. Views support in Drupal 5 works, though.
#2
Proof of concept: I implemented the publish/unpublish part. All comments are welcome
created a file fasttoggle.views.inc inside views/modules
<?php
// $Id: fasttoggle.views.inc,v 1.76 2008/07/02 18:14:03 merlinofchaos Exp $
/**
* @file
* Provide views data and handlers for fasttoggle.module
*/
/**
* Implementation of hook_views_data()
*/
function fasttoggle_views_data() {
$data['node']['publish_node'] = array(
'field' => array(
'title' => t('Publish Node'),
'help' => t('Provide a simple link to publish the node.'),
'handler' => 'views_handler_field_node_link_publish',
),
);
return $data;
}
/**
* Field handler to present a link toggle status.
*/
class views_handler_field_node_link_publish extends views_handler_field_node_link {
function construct() {
parent::construct();
$this->additional_fields['uid'] = 'uid';
$this->additional_fields['status'] = 'status';
$this->additional_fields['type'] = 'type';
$this->additional_fields['format'] = array('table' => 'node_revisions', 'field' => 'format');
}
function render($values) {
// ensure user has access to edit this node.
$node = new stdClass();
$node->nid = $values->{$this->aliases['nid']};
$node->uid = $values->{$this->aliases['uid']};
$node->type = $values->{$this->aliases['type']};
$node->format = $values->{$this->aliases['format']};
$node->status = 1; // unpublished nodes ignore access control
if (!node_access('update', $node)) {
return;
}
$realstatus = $values->{$this->aliases['status']};
if ($realstatus == 1) {
return fasttoggle('unpublish it', 'node/'. $node->nid .'/toggle/status', true, 'status_'. $node->nid);
}
else {
return fasttoggle('publish it', 'node/'. $node->nid .'/toggle/status', true, 'status_'. $node->nid);
}
}
}
#3
The new views API requires:
1. The addition of hook_views_api to fasttoggle.module
function fasttoggle_views_api() {return array('api' => 2);
}
2. Creation of fasttoggle.views.inc file in which you put the "fasttoggle_views_data" function and the "views_handler_field_node_link_publish" class (rename it "fasttoggle_handler_field_node_link_publish") attiks mentioned above.
Put the new file in the fasttoggle modules folder not the views folder.
However, doing that gives a fatal error when the parent class is called "Fatal error: Class 'views_handler_field_node_link' not found."
Only by copying the two parent classes "views_handler_field_node_link" and 'views_handler_field" from the views module and pasting them into fasttoggle.views.inc was I able to make the views integration work. You shouldn't have to do this, but I'm not sure why the parent classes aren't found.
There's also a new hook_views_handlers which defines parents and paths to handlers, but it doesn't seem to help here.
#4
Hey kjl, do you have a patch. I'd be interested in testing/improving it.
#5
I've looked into updating the views support to the D6 version of views, but the developer documentation doesn't seem to be as polished as the end user docs. After about an hour of doing research on the various new hooks, I gave up :/ Of course, I'm always happy to accept patches.
#6
here's a patch but it's ugly
#7
Here's a better patch. It works properly (i.e., it implements hook_views_handlers correctly, so there's no need to copy handlers from the views module like in the previous patch) for the publish/unpublish functionality.
I left the deprecated views code in fasttoggle.module, as the 'comment', 'promote', and 'sticky' handlers still need to be converted.
#8
I haven't tested, but just want to update the status.
#9
a new patch with publish node, promote node and make node sitcky and removing the code for views-1.x.
#10
This patch didn't work for me unless I renamed "fasttoggle_views_data_alter" to "fasttoggle_views_data"
#11
The patch in #9 with the fix in #10 works for me after I created a "fasttoggle/views" folder and moved these files into it:
fasttoggle.views.inc
fasttoggle_handler_field_node_link_promote.inc
fasttoggle_handler_field_node_link_publish.inc
fasttoggle_handler_field_node_link_sticky.inc
Can a few more people test so we can get this checked in?
#12
Confirm, works good
#13
Did not work for me. The implementation of fasttoggle_views_data_alter (which is not documented by the way) was incorrect in the submitted patch. fasttoggle_views_data_alter takes a reference to the data, it is not supposed to return anything. Attached is a working patch. This one is against our codebase using views 2.2. Sorry, no time to check out a fresh copy.
#14
Committed (a modified version of) this patch. Thanks!
#15
Automatically closed -- issue fixed for 2 weeks with no activity.