Commit | Line | Data |
---|---|---|
7f254ad8 AE |
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 | function construct() { | |
16 | parent::construct(); | |
17 | $this->additional_fields['node_vid'] = array('table' => 'node_revision', 'field' => 'vid'); | |
18 | } | |
19 | ||
20 | function access() { | |
21 | return user_access('view revisions') || user_access('administer nodes'); | |
22 | } | |
23 | ||
24 | function render_link($data, $values) { | |
25 | list($node, $vid) = $this->get_revision_entity($values, 'view'); | |
26 | if (!isset($vid)) { | |
27 | return; | |
28 | } | |
29 | ||
30 | // Current revision uses the node view path. | |
31 | $path = 'node/' . $node->nid; | |
32 | if ($node->vid != $vid) { | |
33 | $path .= "/revisions/$vid/view"; | |
34 | } | |
35 | ||
36 | $this->options['alter']['make_link'] = TRUE; | |
37 | $this->options['alter']['path'] = $path; | |
38 | $this->options['alter']['query'] = drupal_get_destination(); | |
39 | ||
40 | return !empty($this->options['text']) ? $this->options['text'] : t('view'); | |
41 | } | |
42 | ||
43 | /** | |
44 | * Returns the revision values of a node. | |
45 | * | |
46 | * @param object $values | |
47 | * An object containing all retrieved values. | |
48 | * @param string $op | |
49 | * The operation being performed. | |
50 | * | |
51 | * @return array | |
52 | * A numerically indexed array containing the current node object and the | |
53 | * revision ID for this row. | |
54 | */ | |
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. | |
59 | $node->status = 1; | |
60 | // Ensure user has access to perform the operation on this node. | |
61 | if (!node_access($op, $node)) { | |
62 | return array($node, NULL); | |
63 | } | |
64 | return array($node, $vid); | |
65 | } | |
66 | } |