| Project: | Views RSS |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
Issue Summary
Hi, all
The purpose of this patch is to allow fields to be mapped to attributes of a tag (eg. ).
My original intent was to find a module that would let me map fields to MRSS tags, but the MRSS support I added is not included here. I'll post it as a comment to this thread later. The focus here is enabling fields-to-attributes for any sort of RSS feed.
I did this through the use of nested field-sets in the forms API:
No attributes: RSS Fieldset > Select Form
Attributes: RSS Fieldset > Tag Fieldset > Select Form
I also made some changes to the way the form is generated in order to make large and unruly forms (such as that required to generate an MRSS feed) with lots of tags and attributes a little less unruly.
I'm not sure if this is the most efficient way of going about what I needed, but it worked for my purposes. Hopefully the community will find some use for it :)
| Attachment | Size |
|---|---|
| views_rss-nested_fieldsets.patch | 13.48 KB |
Comments
#1
Using the above patch, I added support for MRSS tags as follows:
[EDIT] - Removed the wall of text - it was sort of in the way of replies.
Also the code that was here has been consolidated into the below patch - views-rss_nested-fieldsets-2.patch
#2
Ah, forgot to added code tags around my example in the initial issue description.
It was: (eg.
<media:content url="http://url-to-video" />)#3
I've re-rolled this into a single patch and refactored your original code a bit to be in line with coding standards.
This does seem to be working for me and is a great enhancement to the existing views_rss functionality.
#4
I notice your patch applies to "master" rather than 6.x-1.x - is that preferred when creating patches? I'm not yet very familiar with Git or the Drupal community.
Regarding the consolidation of MRSS into the patch: I'm worried that large numbers of MRSS elements and element-attributes might be a bit overbearing for what seems to be a fairly limited use-case that few people might need. I, personally, also use a number of obscure elements in the Boxee and Brightcove namespaces that create an even further limited use-case.
I think the challenge we have here is in providing flexibility for possible elements and namespaces. Adding large numbers of potentially obscure elements to the module doesn't seem like an ideal solution to me, but neither does having developers go in and add the elements themselves via the Drupal Forms API. Any ideas?
#5
I honestly don't know what you guys are talking about but Views RSS with the patch helped me resolve a problem I've been having with Cooliris and Drupal's Media RSS feeds. Thanks!
I did have some problems getting the patch to work until I cloned the Views RSS git repository. I used drush to manage my installation. The instructions for this (and patching) can be found here: http://drupal.org/node/584688/git-instructions/master.
#6
Actually the patch was made against the 6.x-1.x branch. Whichever branch is being actively maintained is the one that the patch should be made against.
An alternative approach to sticking the MRSS stuff (and any other fields people may eventually want) in views_rss is to provide a drupal_alter() callback so other modules can add/edit the fields that will be displayed.
#7
drupal_alter() works quite well, but I can't help but feel like I'm abusing its power by passing in a reference to the entire class so that I can use its methods... is that an issue? Here's what I've been doing:
In views_plugin_style_rss_fields.inc - within function options_form()
<?php
// Use drupal_alter() to open up the form to outside modules.
$form_reference = array(
'this_ref' => &$this,
'form' => &$form,
'field_names' => &$field_names
);
drupal_alter('rss_form', $form_reference);
?>
In a new custom module - views_rss_extension.module
<?php
function views_rss_extension_rss_form_alter($form_reference) {
// Grab some items by reference so that we can muck about and use their methods.
$this_ref = &$form_reference['this_ref'];
$form = &$form_reference['form'];
$field_names = &$form_reference['field_names'];
/**
* MRSS Fieldsets
*/
$mrss_outer = array(
'#type' => 'fieldset',
'#title' => 'MRSS Fields',
'#description' => t('Select fields to be mapped to MRSS Elements.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => 5,
);
$form['mrss'] = $this_ref->buildform('mrss', $mrss_outer, mrss_fieldsets(), $field_names);
}
function mrss_fieldsets() {
return array(
/* [omitted for brevity] */
);
}
?>
#8
This patch uses drupal_alter() as described above to open up the forms and options to outside modules that could act as "extensions" to views_rss.
I've also attached an example of one such extension, which adds television-specific MRSS elements to views_rss, allowing output of a video sitemap as defined by Bing: Video RSS Reference
This seems to be working well for us, and I believe this is the solution we'll be sticking with (assuming no one finds any major bugs in this solution).
Thank you all for your input.
#9
Support for tags with attributes and self-closing tags has been added in both 2.x versions, together with alter hooks providing possibility for other modules to modify existing / add new feed elements and namespaces.
For example implementations, have a look at channel
<source>or item<enclosure>elements in views_rss_core module (submodule of Views RSS, included in its package).Documentation on how to use mentioned hooks is on its way.