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

kkaefer - July 30, 2008 - 19:15

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

#2

attiks - August 13, 2008 - 13:38

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

kjl - November 10, 2008 - 20:03

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

derjochenmeyer - November 19, 2008 - 14:44

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

#5

kkaefer - November 19, 2008 - 14:46

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

kjl - December 5, 2008 - 23:51

here's a patch but it's ugly

AttachmentSize
patch.txt 9.24 KB

#7

kjl - December 9, 2008 - 04:57

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.

AttachmentSize
patch.txt 3.21 KB

#8

greggles - January 29, 2009 - 03:02
Status:active» needs review

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

#9

malaussene - January 29, 2009 - 08:21

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

AttachmentSize
fasttoggle-6.x_with_views-2.x.patch 7.04 KB

#10

kjl - February 10, 2009 - 17:30

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

#11

criznach - February 26, 2009 - 01:05

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

attiks - February 27, 2009 - 15:45

Confirm, works good

#13

nick.dap - March 31, 2009 - 02:48

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.

AttachmentSize
fasttoggle-6.x_with_views-2.x.patch 6.37 KB

#14

kkaefer - March 31, 2009 - 12:12
Status:needs review» fixed

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

#15

System Message - April 14, 2009 - 12:20
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.