diff --git a/CHANGELOG.txt b/CHANGELOG.txt index ac00fa121dbd85df9cff5a575202f70dc6622e0b..27032e36410899915439f4c165555e72de6c548c 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 24cb7f5eff3f856a8878e5d9936562587c3e5765..e40868dbb360c3b22d657fde65d1eefa2c5ca758 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 0000000000000000000000000000000000000000..44bd7033e65f6e2a2ca4ba9b174d66de29974d94 --- /dev/null +++ b/modules/comment/views_handler_field_comment_node_link.inc @@ -0,0 +1,63 @@ +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')) : ''; + } +} +