Accessing content for a specific node revision via a relationship in Views

A module I’ve written implements hooks defined by the Field API to provide a custom field for defining references to specific node revisions by storing vids. (The module borrows functionality from the Entity Reference, Node Reference and Node Revision Reference modules.)

I have a requirement for “parent” nodes to reference a specific version of one or more “child” nodes. The child node(s) may be modified (i.e. new revisions created) after a reference to it is stored against a parent node. It’s essential that the reference on the parent node continues to refer to the same revision of the child node unless the reference is manually updated to a newer revision by a user with sufficient permissions.

I’m currently working on Views integration for the field defined by my module. When creating displays containing one or more parent nodes, I’d also like to be able to display field data for any referenced revisions of child nodes. I’ve defined the following relationship in my module:

/**  * Implements hook_field_views_data().  */ function mymodule_field_views_data($field) {   $data = field_views_field_default_views_data($field);    // Get database table info for $field.   $storage = $field['storage']['details']['sql'];    foreach ($storage as $table_data) {     $table = key($table_data);     $columns = current($table_data);     $id_column = $columns['vid'];      if (isset($data[$table])) {       // Relationship: node revision referenced from $field.       $data[$table][$id_column]['relationship'] = array(         'title' => t('Referenced node revision'),         'label' => t('Node revision referenced from !field_name', array(           '!field_name' => $field['field_name'],         )),         'help' => t('A bridge to the node revision that is referenced via !field_name.', array(           '!field_name' => $field['field_name'],         )),         'group' => t('Node revision reference'),         'handler' => 'views_handler_relationship',         'base' => 'node',         'base field' => 'vid',       );     }   }    return $data; } 

This relationship allows me to display field content for child nodes where the referenced revision is the current revision. However, if an old revision is being referenced by a parent node, the field data is empty. This behaviour occurs when I create a view displaying either content or content revisions.

Does anyone know of a way of accessing field data for a specific node revision via a relationship in Views regardless of whether it’s the current revision or not?

Thanks in advance to anyone who can offer any suggestions!

This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

Accessing content for a specific node revision via a relationship in Views

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.