I did search for an existing issue on this, but didn't find one, so sorry if this is a dupe.

I have a table view, which obviously has to use 'fields' rather than the 'teaser' row style. I added the views field 'add comment link' to the view, and since I also wanted to display both an add comment link and the current comment count, I opted to not use the 'Show teaser-style link' option and added the 'node: comment count' field instead.

My view displays 2 different content types - news and questions - both with comments enabled. For the news content type the requirement was that the add comment form would display on a separate page, whereas for the question content type the form was to appear at the bottom of the full node page.

The above configuration resulted in 'add comment' links appearing for just the news content type and not for the question content type. The reason is that views uses the comment_link() function provided by core to generate the link. This works in every case except where you're (a) not using the teaser-style link and (b) have configured your content type to have the form on the same page.

Not sure where to go from here. I can't just add a manual link to comment/reply/[nid] as that does no permission checking - and I rather like the 'login or register to post comments' link that appears when logged out. Modifying core is obviously not an option, nor is changing my configuration to display all comment forms on a separate page. Ideally I'd like for views to be able to handle this scenario, which would mean adding a lot more logic to views_handler_field_comment_node_link.inc Are you open to this idea? Or should I write a custom field handler?

Cheers,
Stella

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

merlinofchaos’s picture

I'm open to loosening the Views' add comment link a little so that it can handle this scenario. I don't think anybody thought about that case.

stella’s picture

Status: Active » Needs review
FileSize
1.53 KB

Took me a while to get to it, but here's the patch.

merlinofchaos’s picture

Status: Needs review » Needs work

Shouldn't this do permissions checking? It's testing the edge case and then just throwing the link out there, but not actually testing to see if the user has permission to add the comment?

stella’s picture

Ah good point, it should call user_access('post comments') before it. It looks like comment_link() doesn't check against 'post comments without approval' permission, so I guess we don't need to either.

merlinofchaos’s picture

I believe it also needs to test to see if the node even has comments enabled, too.

dawehner’s picture

This patch seems to be commited already.

dawehner’s picture

My last comment it totally wrong.

aenw’s picture

I also ran into this case. I'm using the Node Comments module to use a (CCK) Comment node instead of the Drupal default comments.

Here's the patch with some conditional code surrounding it that checks user permission to post comments (user_access('post comments') ) and that the node can have new comments written (node_comment_mode($node->nid) == COMMENT_NODE_READ_WRITE) ).

[This is my first attempt at a patch. Please let me know if I need to do something to improve.]

MustangGB’s picture

Status: Needs work » Closed (won't fix)