1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Definition of views_handler_field_node_revision.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Contains the basic 'node_revision' field handler.
|
10
|
*
|
11
|
* @ingroup views_field_handlers
|
12
|
*/
|
13
|
class views_handler_field_node_revision extends views_handler_field_node {
|
14
|
|
15
|
/**
|
16
|
* {@inheritdoc}
|
17
|
*/
|
18
|
public function init(&$view, &$options) {
|
19
|
parent::init($view, $options);
|
20
|
if (!empty($this->options['link_to_node_revision'])) {
|
21
|
$this->additional_fields['vid'] = 'vid';
|
22
|
$this->additional_fields['nid'] = 'nid';
|
23
|
if (module_exists('translation')) {
|
24
|
$this->additional_fields['language'] = array('table' => 'node', 'field' => 'language');
|
25
|
}
|
26
|
}
|
27
|
}
|
28
|
|
29
|
/**
|
30
|
* {@inheritdoc}
|
31
|
*/
|
32
|
public function option_definition() {
|
33
|
$options = parent::option_definition();
|
34
|
$options['link_to_node_revision'] = array('default' => FALSE, 'bool' => TRUE);
|
35
|
return $options;
|
36
|
}
|
37
|
|
38
|
/**
|
39
|
* Provide link to revision option.
|
40
|
*/
|
41
|
public function options_form(&$form, &$form_state) {
|
42
|
$form['link_to_node_revision'] = array(
|
43
|
'#title' => t('Link this field to its content revision'),
|
44
|
'#description' => t('This will override any other link you have set.'),
|
45
|
'#type' => 'checkbox',
|
46
|
'#default_value' => !empty($this->options['link_to_node_revision']),
|
47
|
);
|
48
|
parent::options_form($form, $form_state);
|
49
|
}
|
50
|
|
51
|
/**
|
52
|
* Render whatever the data is as a link to the node.
|
53
|
*
|
54
|
* Data should be made XSS safe prior to calling this function.
|
55
|
*/
|
56
|
public function render_link($data, $values) {
|
57
|
if (!empty($this->options['link_to_node_revision']) && $data !== NULL && $data !== '') {
|
58
|
$this->options['alter']['make_link'] = TRUE;
|
59
|
$nid = $this->get_value($values, 'nid');
|
60
|
$vid = $this->get_value($values, 'vid');
|
61
|
$this->options['alter']['path'] = 'node/' . $nid;
|
62
|
if ($nid != $vid) {
|
63
|
$this->options['alter']['path'] .= "/revisions/$vid/view";
|
64
|
}
|
65
|
if (module_exists('translation')) {
|
66
|
$language = $this->get_value($values, 'language');
|
67
|
$languages = language_list();
|
68
|
if (isset($languages[$language])) {
|
69
|
$this->options['alter']['language'] = $languages[$language];
|
70
|
}
|
71
|
}
|
72
|
}
|
73
|
else {
|
74
|
return parent::render_link($data, $values);
|
75
|
}
|
76
|
return $data;
|
77
|
}
|
78
|
|
79
|
}
|