summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEarl Miles2009-04-08 06:38:41 (GMT)
committer Earl Miles2009-04-08 06:38:41 (GMT)
commit7eb44ff2d7fd57877a40bf5465c9c4aee3921b6d (patch)
tree15a9cdb7e5c3ab718ddbb5e6fccf389bcb01ddb3
parent2d4a7d167c28666ef069dc2e8bb3b4ede7534587 (diff)
#400914 by joachim: Add a link field to get to comments for a node that works just like the normal links.
-rw-r--r--CHANGELOG.txt1
-rw-r--r--modules/comment.views.inc11
-rw-r--r--modules/comment/views_handler_field_comment_node_link.inc63
3 files changed, 75 insertions, 0 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index ac00fa1..27032e3 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -7,6 +7,7 @@ Views 2.5
Other changes:
o #379382 by neochief: Add option to strip tags during advanced rendering.
+ o #400914 by joachim: Add a link field to get to comments for a node that works just like the normal links.
Views 2.4
Bugs fixed:
diff --git a/modules/comment.views.inc b/modules/comment.views.inc
index 24cb7f5..e40868d 100644
--- a/modules/comment.views.inc
+++ b/modules/comment.views.inc
@@ -198,6 +198,14 @@ function comment_views_data() {
),
);
+ $data['comments']['node_link'] = array(
+ 'field' => array(
+ 'title' => t('Node link'),
+ 'help' => t('Display the standard comment link used on regular nodes.'),
+ 'handler' => 'views_handler_field_comment_node_link',
+ ),
+ );
+
$data['comments']['thread'] = array(
'field' => array(
'title' => t('Depth'),
@@ -444,6 +452,9 @@ function comment_views_handlers() {
'views_handler_field_comment_link_reply' => array(
'parent' => 'views_handler_field_comment_link',
),
+ 'views_handler_field_comment_node_link' => array(
+ 'parent' => 'views_handler_field',
+ ),
'views_handler_field_ncs_last_comment_name' => array(
'parent' => 'views_handler_field',
),
diff --git a/modules/comment/views_handler_field_comment_node_link.inc b/modules/comment/views_handler_field_comment_node_link.inc
new file mode 100644
index 0000000..44bd703
--- /dev/null
+++ b/modules/comment/views_handler_field_comment_node_link.inc
@@ -0,0 +1,63 @@
+<?php
+// $Id$
+/**
+* Handler for showing comment module's node link.
+ */
+class views_handler_field_comment_node_link extends views_handler_field {
+ function construct() {
+ parent::construct();
+
+ // Add the node fields that comment_link will need..
+ $this->additional_fields['nid'] = array(
+ 'table' => 'node',
+ 'field' => 'nid',
+ );
+ $this->additional_fields['type'] = array(
+ 'table' => 'node',
+ 'field' => 'type',
+ );
+ $this->additional_fields['comment'] = array(
+ 'table' => 'node',
+ 'field' => 'comment',
+ );
+ }
+
+ function option_definition() {
+ $options = parent::option_definition();
+ $options['teaser'] = array('default' => 0);
+ return $options;
+ }
+
+ function options_form(&$form, &$form_state) {
+ parent::options_form($form, $form_state);
+
+ $form['teaser'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Show teaser-style link'),
+ '#default_value' => $this->options['teaser'],
+ '#description' => 'Show the comment link in the form used on standard node teasers, rather than the full node form.',
+ );
+
+ }
+
+ function query() {
+ $this->ensure_my_table();
+ $this->add_additional_fields();
+ }
+
+ function render($values) {
+ // Build fake $node.
+ $node = new stdClass();
+ $node->nid = $values->{$this->aliases['nid']};
+ $node->type = $values->{$this->aliases['type']};
+ $node->comment = $values->{$this->aliases['comment']};
+
+ // Call comment.module's hook_link: comment_link($type, $node = NULL, $teaser = FALSE)
+ $links = comment_link('node', $node, $this->options['teaser']);
+ // question: should we run these through: drupal_alter('link', $links, $node);
+ // might this have unexpected consequences if these hooks expect items in $node that we don't have?
+
+ return !empty($links) ? theme('links', $links, array('class' => 'links inline')) : '';
+ }
+}
+