tags:

views:

509

answers:

3

Trying to modify the RSS feeds created by Views module in Drupal.

Since there are no 'theme_' hooks for the RSS feeds (rightfully as XML is theme-less), I need an alternate way to modify the fields that are output into the RSS, preferably using template.php if possible.

http://api.drupal.org/api/function/format_rss_item/6 looks promising as that is where each row is created, but it doesn't

node_feed() is what collects the nodes, creates the additional fields, and then calls format_rss_item().

Specifically, we need to remove the dc:creator element from the $extra array created in node_feed()

A: 

I'd suggest using the Views Node Feed module to do this. It will let you completely write the XML that is output by Views for feeds.

theunraveler
This wold work but the module is still in development for Drupal 6 and does not fully implement the view_plugin_style Class's interface, giving errors.
Montana Harkin
A: 

In the view, if you click on "style information" this will show you the template files used to create the feed. You can copy the template so that it is overridden for your view and remove dc:creator from the $item_elements array.

This is not particularly nice as you are modifying data in the theme layer, but it will do what you want.

Jeremy French
This would have worked too, but we ended up using contemplate to style the content type that was in the feeds. I think this is the best solution at the moment as you can affect the exact RSS feeds you need, all of them or one of them.
Montana Harkin
A: 

I am adding another answer, as I have recently had to do this and managed to do it without modifying data in the theme layer.

You can add a preprocess function to your view. It is a bit of work though.

There are some guidelines here, but they are a bit confusing. Here is my summary of how to do this.

First make sure your modules weight is > views

Secondly copy the template you would like to add a preprocessor to to your modules directory. Rename it to be something in the list of templates in theming information.

Then edit hook theme like this (but change to use the existing view that you need to override.

function mymodule_theme($existing, $type, $theme, $path) {
  // Copy the exsisting views theme from the existing array.
  $override = $existing['views_view_row_rss'];
  // Add my preprocessor to the list of preprocess functions
  $override['preprocess functions'][] = 'mymodule_myfunction';
  // Point to a template so that this view will be used.
  $override['template'] = 'my_more_specific_template_name';
  $override['path'] = drupal_get_path('module', 'path');
  unset($override['file']);
  // Return your theme handler.
  return array('my_more_specific_template_name' => $override);
}

You should then be able to write your preprocess code in the function mymodule_myfunction.

Jeremy French