5 * Definition of views_handler_field_comment_node_link.
9 * Handler for showing comment module's node link.
11 * @ingroup views_field_handlers
13 class views_handler_field_comment_node_link extends views_handler_field_entity {
14 function construct() {
17 // Add the node fields that comment_link will need..
18 $this->additional_fields['nid'] = array(
21 $this->additional_fields['type'] = array(
24 $this->additional_fields['comment'] = array(
29 function option_definition() {
30 $options = parent::option_definition();
31 $options['teaser'] = array('default' => FALSE, 'bool' => TRUE);
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.'),
43 parent::options_form($form, $form_state);
47 $this->ensure_my_table();
48 $this->add_additional_fields();
51 function render($values) {
53 $node = $this->get_value($values);
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?
61 // Only render the links, if they are defined.
62 return !empty($node->content['links']['comment']) ? drupal_render($node->content['links']['comment']) : '';