Removing translation directories
[project/views.git] / modules / comment / views_handler_field_comment_node_link.inc
1 <?php
2 /**
3 * Handler for showing comment module's node link.
4 */
5 class views_handler_field_comment_node_link extends views_handler_field {
6 function construct() {
7 parent::construct();
8
9 // Add the node fields that comment_link will need..
10 $this->additional_fields['nid'] = array(
11 'table' => 'node',
12 'field' => 'nid',
13 );
14 $this->additional_fields['type'] = array(
15 'table' => 'node',
16 'field' => 'type',
17 );
18 $this->additional_fields['comment'] = array(
19 'table' => 'node',
20 'field' => 'comment',
21 );
22 }
23
24 function option_definition() {
25 $options = parent::option_definition();
26 $options['teaser'] = array('default' => 0);
27 return $options;
28 }
29
30 function options_form(&$form, &$form_state) {
31 parent::options_form($form, $form_state);
32
33 $form['teaser'] = array(
34 '#type' => 'checkbox',
35 '#title' => t('Show teaser-style link'),
36 '#default_value' => $this->options['teaser'],
37 '#description' => 'Show the comment link in the form used on standard node teasers, rather than the full node form.',
38 );
39
40 }
41
42 function query() {
43 $this->ensure_my_table();
44 $this->add_additional_fields();
45 }
46
47 function render($values) {
48 // Build fake $node.
49 $node = new stdClass();
50 $node->nid = $values->{$this->aliases['nid']};
51 $node->type = $values->{$this->aliases['type']};
52 $node->comment = $values->{$this->aliases['comment']};
53
54 // Call comment.module's hook_link: comment_link($type, $node = NULL, $teaser = FALSE)
55 $links = comment_link('node', $node, $this->options['teaser']);
56 // question: should we run these through: drupal_alter('link', $links, $node);
57 // might this have unexpected consequences if these hooks expect items in $node that we don't have?
58
59 return !empty($links) ? theme('links', $links, array('class' => 'links inline')) : '';
60 }
61 }
62