Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I added it in my own module, but it might be nice to have it provided with views.
/**
* Define extra fields used in Views
*/
function simon_views_tables() {
$tables['simon'] = array(
'name' => 'simon',
'fields' => array(
'add_comment' => array(
'name' => t('Comment: Add link'),
'handler' => 'views_handler_comment_add',
'notafield' => TRUE,
'option' => 'string',
'help' => t('Display a link to add a comment to the node. Enter the text of this link into the option field; if blank the default "Comment" will be used.'),
)
)
);
return $tables;
}
/**
* display a link to add a comment to a node
*/
function views_handler_comment_add($fieldinfo, $fielddata, $value, $data) {
// try to build a fake node object
$data->type = $data->node_type;
$data->uid = $data->node_uid;
if (node_access('update', $data)) {
$link_text = $fielddata['options'] ? $fielddata['options'] : t('Comment');
return l($link_text, "comment/reply/$data->nid#comment-form");
}
}
Requires node+comment modules, I guess
Comment | File | Size | Author |
---|---|---|---|
#2 | views_comment.inc_.patch | 1.25 KB | lyricnz |
Comments
Comment #1
lyricnz CreditAttribution: lyricnz commentedHehe, you can see that I cut'n'paste from the node-edit code. The node_access() check in views_handler_comment_add() should probably be user_access('post comments')
Comment #2
lyricnz CreditAttribution: lyricnz commentedSee attached patch, should apply to 5.x or HEAD
Comment #3
lyricnz CreditAttribution: lyricnz commentedTo "code needs review"
Comment #4
merlinofchaos CreditAttribution: merlinofchaos commentedLooks good enough. Applied! Thanks!
Comment #5
(not verified) CreditAttribution: commentedComment #6
deshilachado CreditAttribution: deshilachado commentedWill this be included in the 6-branch also?
I really need a field with node:add-comment-link
Comment #8
WorldFallz CreditAttribution: WorldFallz commentedspammers are getting out of control :-(