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.

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.

  • 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. – John Mitchell Dec 10 '14 at 19:34
  • Have you tried clearing the cache, a lot of views options are cached. Also, have you reverted your hack ? – jowan sebastian Dec 10 '14 at 19:39
  • Yes I have cleared the drupal cache many times and the hack was also reverted. – John Mitchell Dec 10 '14 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. – jowan sebastian Dec 11 '14 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. – John Mitchell Dec 11 '14 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.

  • I also previously tried moving the hook_views_query_alter call to a custom module but it did not make any difference. – John Mitchell Dec 8 '14 at 2:45
  • I assume you did the usual things like changing the function name to match the module...? – Darvanen Dec 8 '14 at 3:15
  • Yes I have changed the function name to match the module – John Mitchell Dec 8 '14 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. – jowan sebastian Dec 12 '14 at 0:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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