Has anyone already integrated this module with views to filter based on the lm_paypal_subscribers status field?
I've been trying to get this working but haven't had great success yet.
This is my first attempt at adding views support to a module.
So far I've added the views hook to the lm_paypal.module, or should this go in lm_paypal_paid_adverts.module file? either one?
/**
* Implementation of hook_views_api().
*/
/*function lm_paypal_views_api() {
return array('api' => 2.0);
}
And I've created the lm_paypal.views.inc file but have not been able to get it working yet.
Should this be lm_paypal.views.inc or lm_paypal_paid_adverts.views.inc ?
Is this code anywhere near correct? Suggestions please? I'm not sure if this needs to be a base table, I believe I set up the join correctly. But nothing has showed up in the views filters yet.
<?php
// $Id: lm_paypal.views.inc,v 0.01 2009/3/02 22:51:23 internets Exp $
/**
* @file
* Views 2 support for lm_paypal
*/
/*
TODO:
* Test
* Finish adding views support
/**
* Implementation of hook_views_handlers().
*/
function lm_paypal_views_handlers() {
return array(
'handlers' => array(
'lm_paypal_handler_filter_lm_paypal_subscribers_status' => array(
'parent' => 'views_handler_filter',
),
),
);
}
/**
* Implementation of hook_views_data().
*/
function lm_paypal_views_data() {
$data['lm_paypal_subscribers']['status'] = array(
'title' => t('Subscription status'),
'help' => t('Paypal subscription status.'),
'field' => array(
'handler' => 'lm_paypal_views_handler_field_status',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
$data['lm_paypal_subscribers']['table']['group'] = t('Paypal Subscriptions');
// Advertise this table as a possible base table
$data['lm_paypal_subscribers']['table']['base'] = array(
'field' => 'usid',
'title' => t('Paypal paid adverts'),
'help' => t("Paypal paid advert subscriptions."),
'weight' => -10,
);
$data['lm_paypal_subscribers']['table']['join']['node'] = array(
'left_field' => 'nid',
'field' => 'nid',
);
$data['lm_paypal_subscribers']['status'] = array(
'title' => t('Paypal subscription status'),
'help' => t('The status code of the paypal subscription.'), // The help that appears on the UI,
// Information for displaying the nid
'field' => array(
'handler' => 'views_handler_field_lm_paypal_subscribers',
'click sortable' => TRUE,
),
// Information for accepting a nid as an argument
'argument' => array(
'handler' => 'views_handler_argument_lm_paypal_subscribers_status',
// 'name field' => 'title', // the field to display in the summary.
'numeric' => TRUE,
'validate type' => 'status',
),
// Information for accepting a nid as a filter
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
// Information for sorting on a nid.
'sort' => array(
'handler' => 'views_handler_sort',
),
);
return $data;
}
Comments
Comment #1
lyricnz commentedSeems like there are a bunch of different fields/filters that LM Paypal uses that could be exposed to Views (yay). We've been meaning to do this for a while.
You must be careful not to make assumptions about which modules are enabled - in particular subscription information should only be accessed from lm_paypal_subscriptions (or a module that depends on that).
PS: we're not going to do significant new development in the 6.x-1.x branch - all our (cool) new stuff is in 6.x-2.x.
Comment #2
internets commentedThanks for the response, I'm now updated to the 6.x-2.0-alpha release and will continue working with that. It all appears to be running nicely, upgrade went smooth.
Good point about making assumptions as to which parts of lm_paypal are enabled.
I'm trying to get this working but have not yet gotten a single thing to show up in the views UI.
I've been following along with http://views-help.doc.logrus.com/help/views/api and http://views.doc.logrus.com/group__views__hooks.html#g227057901681e4a33e...
I'm just trying to get the group to at least show up in the list of available filters and or fields.
Any suggestions for what is missing / wrong? Are there any other helpful examples of adding support for views 2 to a module?
And the lm_paypal.views.inc file which should be automatically included