1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Definition of views_handler_field_comment_node_link.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Handler for showing comment module's node link.
|
10
|
*
|
11
|
* @ingroup views_field_handlers
|
12
|
*/
|
13
|
class views_handler_field_comment_node_link extends views_handler_field_entity {
|
14
|
|
15
|
/**
|
16
|
* {@inheritdoc}
|
17
|
*/
|
18
|
public function construct() {
|
19
|
parent::construct();
|
20
|
|
21
|
// Add the node fields that comment_link will need.
|
22
|
$this->additional_fields['nid'] = array(
|
23
|
'field' => 'nid',
|
24
|
);
|
25
|
$this->additional_fields['type'] = array(
|
26
|
'field' => 'type',
|
27
|
);
|
28
|
$this->additional_fields['comment'] = array(
|
29
|
'field' => 'comment',
|
30
|
);
|
31
|
}
|
32
|
|
33
|
/**
|
34
|
* {@inheritdoc}
|
35
|
*/
|
36
|
public function option_definition() {
|
37
|
$options = parent::option_definition();
|
38
|
$options['teaser'] = array('default' => FALSE, 'bool' => TRUE);
|
39
|
return $options;
|
40
|
}
|
41
|
|
42
|
/**
|
43
|
* {@inheritdoc}
|
44
|
*/
|
45
|
public function options_form(&$form, &$form_state) {
|
46
|
$form['teaser'] = array(
|
47
|
'#type' => 'checkbox',
|
48
|
'#title' => t('Show teaser-style link'),
|
49
|
'#default_value' => $this->options['teaser'],
|
50
|
'#description' => t('Show the comment link in the form used on standard node teasers, rather than the full node form.'),
|
51
|
);
|
52
|
|
53
|
parent::options_form($form, $form_state);
|
54
|
}
|
55
|
|
56
|
/**
|
57
|
* {@inheritdoc}
|
58
|
*/
|
59
|
public function query() {
|
60
|
$this->ensure_my_table();
|
61
|
$this->add_additional_fields();
|
62
|
}
|
63
|
|
64
|
/**
|
65
|
* {@inheritdoc}
|
66
|
*/
|
67
|
public function render($values) {
|
68
|
// Build fake $node.
|
69
|
$node = $this->get_value($values);
|
70
|
|
71
|
// Call comment.module's hook_link:
|
72
|
// comment_link($type, $node = NULL, $teaser = FALSE)
|
73
|
// Call node by reference so that something is changed here.
|
74
|
comment_node_view($node, $this->options['teaser'] ? 'teaser' : 'full');
|
75
|
// Question: should we run these through:
|
76
|
// drupal_alter('link', $links, $node);
|
77
|
// Might this have unexpected consequences if these hooks expect items in
|
78
|
// $node that we don't have?
|
79
|
|
80
|
// Only render the links, if they are defined.
|
81
|
return !empty($node->content['links']['comment']) ? drupal_render($node->content['links']['comment']) : '';
|
82
|
}
|
83
|
|
84
|
}
|