1

I have applied this patch to the Views module so that it will add the channel properties of pubDate and lastBuildDate.

Then I ran Drupal "Clear all caches" within /admin/config/development/performance.

The added channel properties are only available for the first page requested each time after running another Drupal "Clear all caches".

For Drupal 7 how can I ensure that views RSS channel properties that are added with hook_views_query_alter() remain?

=================================================================================

I have already tried the “Views RSS” module and after downloading and enabling this module along with its associated “views_rss_core” the “RSS Feed – Fields” radio button does not display and only the “RSS Feed” option is present which comes from the “Views” module.

0

2 Answers 2

1

You can do this with Views RSS 2 and hook_views_rss_item_elements().

As we can see in the documentation for Views RSS API views_rss_get it can :

Fetch item elements provided by other modules.

So to create your own item element do the following :

  • First thing, revert your hack, it won't be needed.
  • Download and install the module Views RSS (and Core Elements, DC Elements)
  • Create a default view for content and fields
  • Add a feed to it
  • Style it as RSS Feed - Fields
  • In the settings pubDate is avaible alerady so we don't have to worry about that.

Create a tiny module and enter the following

/**
 * Implements hook_views_rss_namespaces().
 */
function MY_MODULE_views_rss_item_elements() {
  $elements['dc:lastBuildDate'] = array(
    'description' => t('My custom lastBuildDate field.'),
    'help' => '',
  );
  return $elements;
}

Then install it and clear your cache.

Now, in the Views RSS field settings there should be a new field for your custom field (see image)

enter image description here

And when you view your feed it should be included (see image - last line)

enter image description here

Note: if you look at the snippet, it adds the field to the dc namespace. If you want to use another or provide your own namespaces have a look at the API and hooks.

5
  • I have already tried the “Views RSS” module and after downloading and enabling this module along with its associated “views_rss_core” the “RSS Feed – Fields” radio button does not display and only the “RSS Feed” option is present which comes from the “Views” module. Dec 10, 2014 at 19:34
  • Have you tried clearing the cache, a lot of views options are cached. Also, have you reverted your hack ? Dec 10, 2014 at 19:39
  • Yes I have cleared the drupal cache many times and the hack was also reverted. Dec 10, 2014 at 23:29
  • Not sure why the radio button is not there. Maybe disable then uninstall Views Rss module to see if it reacreates it. Just to confirm this solution though, please try the above on a fresh install, it might help you track down what's wrong. Dec 11, 2014 at 9:10
  • I disabled and uninstalled views rss for both the recommended and the dev version and I still don't see the radio button. Dec 11, 2014 at 13:52
-1

It appears to me that you have custom patched the Views modules with an extra function which calls hook_views_query_alter. There are at least two problems with doing it this way:

  1. Altering a module with a patch that is not being considered for commit by the maintainers will lead to trouble when the module is updated - in a few years when somebody else is maintaining the site, will they remember to apply the same or an updated patch each time? Will you?
  2. The views module may already have a hook_views_query_alter call and you can't call a hook more than once in any one module. If it doesn't, maybe it will have one in later versions.

I suggest moving your code to a custom module.

4
  • I also previously tried moving the hook_views_query_alter call to a custom module but it did not make any difference. Dec 8, 2014 at 2:45
  • I assume you did the usual things like changing the function name to match the module...?
    – Darvanen
    Dec 8, 2014 at 3:15
  • Yes I have changed the function name to match the module Dec 8, 2014 at 11:10
  • 2. if a module had two same hooks they would be same function names and php would throw error - Fatal error: Cannot redeclare etc. so OP would know. Also views exposes this hook (part of it's API), it doesn't implement it itself so it is available. Some good advice here but no answers. Dec 12, 2014 at 0:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.