1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Definition of views_handler_field_node_revision_link.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Field handler to present a link to a node revision.
|
10
|
*
|
11
|
* @ingroup views_field_handlers
|
12
|
*/
|
13
|
class views_handler_field_node_revision_link extends views_handler_field_node_link {
|
14
|
|
15
|
/**
|
16
|
* {@inheritdoc}
|
17
|
*/
|
18
|
public function construct() {
|
19
|
parent::construct();
|
20
|
$this->additional_fields['node_vid'] = array('table' => 'node_revision', 'field' => 'vid');
|
21
|
}
|
22
|
|
23
|
/**
|
24
|
* {@inheritdoc}
|
25
|
*/
|
26
|
public function access() {
|
27
|
return user_access('view revisions') || user_access('administer nodes');
|
28
|
}
|
29
|
|
30
|
/**
|
31
|
* {@inheritdoc}
|
32
|
*/
|
33
|
public function render_link($data, $values) {
|
34
|
list($node, $vid) = $this->get_revision_entity($values, 'view');
|
35
|
if (!isset($vid)) {
|
36
|
return;
|
37
|
}
|
38
|
|
39
|
// Current revision uses the node view path.
|
40
|
$path = 'node/' . $node->nid;
|
41
|
if ($node->vid != $vid) {
|
42
|
$path .= "/revisions/$vid/view";
|
43
|
}
|
44
|
|
45
|
$this->options['alter']['make_link'] = TRUE;
|
46
|
$this->options['alter']['path'] = $path;
|
47
|
$this->options['alter']['query'] = drupal_get_destination();
|
48
|
|
49
|
return !empty($this->options['text']) ? $this->options['text'] : t('view');
|
50
|
}
|
51
|
|
52
|
/**
|
53
|
* Returns the revision values of a node.
|
54
|
*
|
55
|
* @param object $values
|
56
|
* An object containing all retrieved values.
|
57
|
* @param string $op
|
58
|
* The operation being performed.
|
59
|
*
|
60
|
* @return array
|
61
|
* A numerically indexed array containing the current node object and the
|
62
|
* revision ID for this row.
|
63
|
*/
|
64
|
public function get_revision_entity($values, $op) {
|
65
|
$vid = $this->get_value($values, 'node_vid');
|
66
|
$node = $this->get_value($values);
|
67
|
// Unpublished nodes ignore access control.
|
68
|
$node->status = 1;
|
69
|
// Ensure user has access to perform the operation on this node.
|
70
|
if (!node_access($op, $node)) {
|
71
|
return array($node, NULL);
|
72
|
}
|
73
|
return array($node, $vid);
|
74
|
}
|
75
|
|
76
|
}
|