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!