I'm faced with a situation where we need to keep track of which node revision a comment was made for, so that we can display whether the comment was made for a newer/older revision, or for the one currently being looked at. Do any comment modules allow this in D7?

Use cases

  1. Not the actual use case, but a decent, easy-to-follow approximation of the idea: imagine a bookstore, where users can post comments about books. Typically, when a user asks to see a book's page, he sees the page about the book's newest edition, but in some cases a page for an older edition of the book is presented. In the list of comments for the book, comments are annotated with whether they were made about a different edition than the one being currently looked at, since the comment might not be applicable for other editions.

  2. The actual use case is: teacher A creates learning material LM.v1 and then revises it to LM.v2; teacher B starts using LM.v2 with her class; when A revises LM.v2 to LM.v3, we still need to allow B and her class to use LM.v2, because LM.v3 might not work for B's needs at all (and changing a learning material mid-project is a big no-no); so, when looking at LM.v2, we want to be able to see all comments made about it, but with an annotation if the comment was about LM.v1 or LM.v3, since these may or may not be applicable in the LM.v2 case.

  • Did you ever implement a solution? Nov 11 '15 at 1:32
  • We never got around to the commenting, because we never had a good idea what would work reliably in our various situations... Ergo, still a work in progress.
    – Alicja Z
    Nov 19 '15 at 11:48

I'm thinking out loud here... to simplify some aspects, I would probably try something like this first:

  • set up each 'revision' as it's own content
  • add a field that will follow each revision (ie. an internal product code that doesn't change even with revisions)
  • add a Views block to the bottom of the content page for that content type which includes a filter of ALL comments where those comments share the same internal product code but not from the current content - that way direct comments show normally, and then there's a view showing comments from the other revisions
  • Thanks, Geoff - that's an interesting solution we hadn't thought of. Unfortunately, it seems a bit cumbersome for the project we're working on (we also have translations in the works etc - resulting in a lot lot lot of nodes etc). It would probably suit very well someone with a less convoluted project, though. :)
    – Alicja Z
    Jun 30 '14 at 13:59
  • Does your comment basically imply that there is no support for versioning in any comment modules that you know of?
    – Alicja Z
    Jun 30 '14 at 14:01
  • via Core? No, there isn't. I believe there a few modules that allow revisionned comments, but I'm not sure how much they would offer. Search for 'drupal comment revision'
    – Geoff
    Jun 30 '14 at 15:59
  • Thanks... that's what I found too, but I wanted to double check. We've figured out a hook-based hack that should work - will answer this question with it if that's the case, unless someone else comes up with another solution before that...
    – Alicja Z
    Jul 1 '14 at 17:56

Surprising that this isn't addressed anywhere. I have a similar requirement and can't find any modules in this space. There is a Drupal core issue about this but it hasn't received any love.

Somehow, comments (comment.cid) need to be mapped to node versions (node_revision.vid). This could be done with a custom table, or simply use a field on the comment to track vid. Pros and cons either way. Either way, expose to Views as needed, and implement hook_comment_insert() to add an entry to the table/set the field (and similarly hook_comment_delete()).

Since they are all attached to the node though, I think comments would have to be filtered on node view (see related question), which is far from ideal.

I hope to get something working and update this post with more detail.


I ended up going for the field strategy. I added an integer field to the comment fields on my content type (machine name field_comment_node_version), and then added a piece of code to populate it:

* Implements hook_comment_insert().
function MYMODULE_comment_insert($comment) {
  // Populate the comment field for node version
  $node = node_load($comment->nid);
  $wrapper = entity_metadata_wrapper('comment', $comment);

And that's really all there is to it. Now you can use views to get the vid the comment was submitted against.

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.