Views RSS: D7-style formatters in D6

New 6.x-2.x-dev version of Views RSS module has just been pushed to d.o., introducing field formatters returning elements formatted as D7-style extended array.

New 6.x-2.x-dev version of Views RSS module has just been pushed to d.o. Most probably it will soon become rc3, if neither me nor anybody else will find any bugs in it soon (and by "soon" I mean few days until I apply all these changes to D7 version).

Full list of changes can be seen on drupalcode.org, the most important one of them though is that field formatters (both CCK and internal Views ones) return element formatted as D7-style extended array, containing the following keys:

  • #item - original item from which final element is being built,
  • #markup - fully formatted XML element,
  • #rss_element - XML element details compatible with format_xml_elements(), based on which #markup is built.

One thing to keep in mind is that D6 does not know how to deal with such an array returned by a formatter, as it expects to receive final value as a simple string, therefore two simple tricks are being applied before the element is displayed:

  • for elements displayed by Views, new field handler views_rss_handler_field_multiple has been added, which saves the extended array to relevant field data in $view->result and then returns only #markup value,

  • for elements displayed on normal pages, relevant theme function (for example views_rss_core_field_formatter_view() in case of Views RSS: Core Elements module) returns only #markup value instead of full extended array if it detects that it was not called from the view.

This is now used by <category>, <author> and <enclosure> item elements (which, at the same time, do not use preprocess functions anymore, so check your alter functions if you are using ones), and will be added to other formatters in other extension modules as well.

Why? I needed this for progressing with Views RSS: Media (MRSS) Elements module (actually, D7 works this way out of the box, so there was no problem there, but trying to replicate media features in D6 module proved to be impossible originally). Long story, another post.

Other changes worth noting:

  • Taxonomy: All terms has new display type - RSS <category> element, which is no longer based on Separator value being a comma (like it was before), has no problem with commas in tag names and supports domain attribute (essentially, see issue Support "domain" attribute on item categories

  • views-view-views-rss-field.tpl.php template supports $markup variable - if passed it will just be displayed as-is, without processing any other variables afterwards.

Now, on to D7 version.