Is it possible to use the same links as views columns and if so did anyone already created a patch for it?

Cheers
Peter

Comments

kkaefer’s picture

Fasttoggle actually has integration with views, but the APIs probably changed with Views2 for Drupal 6. Views support in Drupal 5 works, though.

attiks’s picture

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);
}
}
}

kjl’s picture

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.

derjochenmeyer’s picture

Hey kjl, do you have a patch. I'd be interested in testing/improving it.

kkaefer’s picture

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.

kjl’s picture

StatusFileSize
new9.24 KB

here's a patch but it's ugly

kjl’s picture

StatusFileSize
new3.21 KB

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.

greggles’s picture

Status: Active » Needs review

I haven't tested, but just want to update the status.

malaussene’s picture

Issue tags: +views
StatusFileSize
new7.04 KB

a new patch with publish node, promote node and make node sitcky and removing the code for views-1.x.

kjl’s picture

This patch didn't work for me unless I renamed "fasttoggle_views_data_alter" to "fasttoggle_views_data"

criznach’s picture

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?

attiks’s picture

Confirm, works good

nick.dap’s picture

StatusFileSize
new6.37 KB

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.

kkaefer’s picture

Status: Needs review » Fixed

Committed (a modified version of) this patch. Thanks!

Status: Fixed » Closed (fixed)

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

doublejosh’s picture

Just updated to the new version. Love the views integration.
However enable/disable comments is not among the Node: XXX (fast toggle) options :(

nigelcunningham’s picture

Please open a new bug, doublejosh and I'll try to find some time to look into it.

doublejosh’s picture

No problem. Thanks for this great module. http://drupal.org/node/1185750

Gabriel R.’s picture

Integration not complete for Comment views?!

  • Commit 24597cc on 6.x-1.x, master by kkaefer:
    #289076: Views 2 support for node links (by attiks, kjl, malaussene and...