5 * Definition of views_handler_field_node_revision_link.
9 * Field handler to present a link to a node revision.
11 * @ingroup views_field_handlers
13 class views_handler_field_node_revision_link extends views_handler_field_node_link {
15 function construct() {
17 $this->additional_fields['node_vid'] = array('table' => 'node_revision', 'field' => 'vid');
21 return user_access('view revisions') || user_access('administer nodes');
24 function render_link($data, $values) {
25 list($node, $vid) = $this->get_revision_entity($values, 'view');
30 // Current revision uses the node view path.
31 $path = 'node/' . $node->nid;
32 if ($node->vid != $vid) {
33 $path .= "/revisions/$vid/view";
36 $this->options['alter']['make_link'] = TRUE;
37 $this->options['alter']['path'] = $path;
38 $this->options['alter']['query'] = drupal_get_destination();
40 return !empty($this->options['text']) ? $this->options['text'] : t('view');
44 * Returns the revision values of a node.
46 * @param object $values
47 * An object containing all retrieved values.
49 * The operation being performed.
52 * A numerically indexed array containing the current node object and the
53 * revision ID for this row.
55 function get_revision_entity($values, $op) {
56 $vid = $this->get_value($values, 'node_vid');
57 $node = $this->get_value($values);
58 // Unpublished nodes ignore access control.
60 // Ensure user has access to perform the operation on this node.
61 if (!node_access($op, $node)) {
62 return array($node, NULL);
64 return array($node, $vid);