commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-new / views / modules / comment / views_handler_field_comment_node_link.inc
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 function construct() {
15 parent::construct();
16
17 // Add the node fields that comment_link will need..
18 $this->additional_fields['nid'] = array(
19 'field' => 'nid',
20 );
21 $this->additional_fields['type'] = array(
22 'field' => 'type',
23 );
24 $this->additional_fields['comment'] = array(
25 'field' => 'comment',
26 );
27 }
28
29 function option_definition() {
30 $options = parent::option_definition();
31 $options['teaser'] = array('default' => FALSE, 'bool' => TRUE);
32 return $options;
33 }
34
35 function options_form(&$form, &$form_state) {
36 $form['teaser'] = array(
37 '#type' => 'checkbox',
38 '#title' => t('Show teaser-style link'),
39 '#default_value' => $this->options['teaser'],
40 '#description' => t('Show the comment link in the form used on standard node teasers, rather than the full node form.'),
41 );
42
43 parent::options_form($form, $form_state);
44 }
45
46 function query() {
47 $this->ensure_my_table();
48 $this->add_additional_fields();
49 }
50
51 function render($values) {
52 // Build fake $node.
53 $node = $this->get_value($values);
54
55 // Call comment.module's hook_link: comment_link($type, $node = NULL, $teaser = FALSE)
56 // Call node by reference so that something is changed here
57 comment_node_view($node, $this->options['teaser'] ? 'teaser' : 'full');
58 // question: should we run these through: drupal_alter('link', $links, $node);
59 // might this have unexpected consequences if these hooks expect items in $node that we don't have?
60
61 // Only render the links, if they are defined.
62 return !empty($node->content['links']['comment']) ? drupal_render($node->content['links']['comment']) : '';
63 }
64 }