1

I wish that my users can leave only one comment per node (including by using the url).

Once their posted comment, I wish that the link "add comment" disappears.

I tried numerous solutions, such as Onecomment or custom code, but all prevent the second comment at the level of the form (form validate), with an error.

I would like for better user experience than it is not upstream possible to click on "add comment".

Do you know a solution ?

2

If you are OK with custom modules, you can make the module below. If you have never made a custom module before, just make a folder called single_comment and create 2 files inside called single_comment.info and single_comment.module then add the code below into the respective files.

single_comment.info

name = Single Comment
description = Allow users to only add one comment to a node.
core = 7.x

single_comment.module

function single_comment_node_load($nodes, $types) {
  global $user;
  if (user_is_logged_in()) {
    foreach ($nodes as $node) {
      $comment_arr = comment_load_multiple(comment_get_thread($node, COMMENT_MODE_FLAT, 100));
      foreach ($comment_arr as $comment) {
        if ($comment->uid == $user->uid) {
          $node->comment = COMMENT_NODE_CLOSED;
          break;
        }
      }
    }
  }
}

You can call the module whatever you like but just remember to replace anywhere single_comment occurs. That includes the folder, file names, name in .info and the function name.

0
1

I've never tried this solution. But it seems like you could

  • Get the username of the current user... with a module such as something like this https://www.drupal.org/node/141110
  • If that user has a comment, hide the add comment button. This presumes that you can figure out the author of the comment (you could potentially override the comment display .tpl to write that into JS, or at least make it easy to pick up with jQuery)

If your users aren't logged in, that would make things a little bit more tricky.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.