Additional fields in feedapi_node_views.module
therzog - July 30, 2008 - 14:58
| Project: | FeedAPI |
| Version: | 6.x-1.x-dev |
| Component: | Code views integration |
| Category: | feature request |
| Priority: | normal |
| Assigned: | alex_b |
| Status: | closed |
Description
Hey guys: here's a patch with 2 additions to feedapi_node_views:
1) Exposes the feed item's original url, with options to display as the node's title with a link
2) Add handler to show parent feed as a link to the side (as opposed to a link to the feed)
This made this view a lot easier: http://www.wri.org/wri-blogs
<?php
-// $Id: feedapi_node_views.module,v 1.1 2008/05/27 18:04:23 devseed Exp $
+// $Id: feedapi_node_views.module,v 1.2 2008/06/06 14:37:40 cvsroot Exp $
/**
* Add views functionality to FeedAPI Node
@@ -21,6 +21,21 @@
'field' => 'nid'
)
),
+ 'fields' => array(
+ 'url' => array(
+ 'name' => t('FeedAPI Item: Original Url'),
+ 'handler' => 'feedapi_node_views_handler_field_url',
+ 'help' => t('The original url for a feed item'),
+ 'option' => array(
+ '#type' => 'select',
+ '#options' => array(
+ 'title_link' => t('Item\'s Title with link'),
+ 'link' => t('With link'),
+ 'nolink' => t('Without link'),
+ ),
+ ),
+ ),
+ ),
'sorts' => array(
'timestamp' => array(
'name' => t('FeedAPI Item: Time of the news item'),
@@ -43,13 +58,14 @@
),
'fields' => array(
'feed_nid' => array(
- 'name' => t('Parent feed'),
+ 'name' => t('FeedAPI: Parent Feed'),
'handler' => 'feedapi_node_views_handler_field_feed_nid',
'option' => array(
'#type' => 'select',
'#options' => array(
'link' => 'As link',
'nolink_to_feeds' => 'As link to feeds',
+ 'link_to_site' => 'As link to site',
'nolink' => 'Without link',
),
),
@@ -80,10 +96,34 @@
elseif ($fielddata['options'] == 'nolink_to_feeds') {
return l($node->title, "feed-item/$node->nid");
}
+ elseif ($fielddata['options'] == 'link_to_site') {
+ return l($node->title, $node->feed->link);
+ }
return l($node->title, "node/$node->nid");
}
/**
+ * url handler
+ */
+function feedapi_node_views_handler_field_url($fieldinfo, $fielddata, $value, $data) {
+
+ $url = $data->feedapi_node_item_url;
+ if( $fielddata['options'] == 'title_link' ) {
+ if( ($node = node_load($data->nid)) ) {
+ return l($node->title, $url);
+ }
+
+ return l(t('n/a'), $url);
+ }
+ elseif( $fielddata['options'] == 'link' ) {
+ return l($url, $url);
+ }
+
+ return check_plain($url);
+}
+
+
+/**
* Implementation of hook_views_arguments().
*/
function feedapi_node_views_views_arguments() {
#1
Thanks,
Reviewed and rerolled. I'm going to use this on production soon. Will commit if I don't run into problems.
#2
Committed. Needs to be ported to 6.x
#3
subscribing to D6 port.
#4
#347526: Full views support, admin/content/feed powered by views has a pretty comprehensive rewrite of the views... i'd suggest closing this and using that as a starting point.
#5
Automatically closed -- issue fixed for two weeks with no activity.