Adding channel <pubDate> and <lastBuildDate> elements for non-core view types
Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites
Definitions provided by Views RSS: Core Elements module
By default, Views RSS: Core Elements will try to generate <pubDate>
and <lastBuildDate>
channel elements for core view types only: Node, Comment, File, Node revision, Term and User.
Please note though that elements that could be generated depend on what data is available for a specific view type:
- Node: both
<pubDate>
and<lastBuildDate>
will be generated, based onnode.created
andnode.changed
database columns, - Comment: only
<lastBuildDate>
will be generated fromcomments.timestamp
database column, - File: only
<pubDate>
will be generated fromfiles.timestamp
database column, - Node revision: only
<pubDate>
will be generated fromnode_revisions.timestamp
database column, - Term: neither
<pubDate>
nor<lastBuildDate>
will be generated, as terms does not store its creation/modification times in the database, - User: only
<pubDate>
will be generated fromusers.created
database column.
Adding new definitions
To add new definitions for other view types, you need to know view's base table and where item's creation and modification dates are stored in the database (which is usually the same table), and implement hook_views_rss_date_sources()
hook provided by Views RSS module.
For example Commerce Products
provided by Drupal Commerce module are stored in commerce_product
database table, with creation date stored in created
column, and modification date in changed
column.
In this case the implementation of hook_views_rss_date_sources()
will look as follows:
/**
* Implements hook_views_rss_date_sources().
*/
function MYMODULE_views_rss_date_sources() {
$sources['commerce_product'] = array(
'pubDate' => array(
'table' => 'commerce_product',
'field' => 'created',
),
'lastBuildDate' => array(
'table' => 'commerce_product',
'field' => 'changed',
),
);
}
In cases when there is no database source for either creation or modification date, relevant key(s) from the array above need to be removed.
Remember about flushing Views cache after making any changes to date sources definitions.
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion