1

My users have the following fields: 'Avatar' (image) and 'Year' (number). When a user leaves a comment, I'd like to display these fields, the username and the user's current userpoints next to each other on top of the comment. The end result should look something like this:

Example of a comment

The fields shouldn't be updated: when they change in the future, they should maintain the value they had at the moment the comment was posted.

How can I achieve this?

  • I think you're going to have a very hard time achieving that. If the value were to just be dynamically updated, that's easy, but to maintain storage of a user's points and the point in time they commented would be quite difficult. – kyletaylored Feb 20 '14 at 14:46
0

I haven't tried this out for sure, so this is kinda just spit balling, but the way I would do this would be to write a small little custom module. So, example:

You could have the date/avatar field stored as a field in the user table. Then in the comments, add both a date/avatar flied to the comment (under /admin/structure/types/manage/[node type]/comment/fields). So now you would have to two places to save the info.

To hook them up, I would write a custom module that uses hook_comment_presave to intercept the date and avatar field before the comment is saved, load the user info from the commenting user, and then replace the comment date/avatar from the user date/avatar. That way, the information that was with the user at the point of commenting will be forever with the comment.

You will of course need to theme it, and you will need to hid those comment fields from the user in the comment form. Your also gonna want to make sure the avatar is persistent, but I think this should be a workable solution. At least, that's where I would start.

  • That actually souds like a great solution: I think one should be able to implement these things quite easily. Mentioning the theming: can you explain in short how/where I should do that? – Jeroen Feb 20 '14 at 15:51
  • 1
    Sure thing. Your probably gonna want to modify the comment.tpl.php file (should be located in your theme file somewhere, if it's not, then you'll need to copy the file in /modules/comment/comment.tpl.php to your theme. Make sure you copy it and make any changes to your theme, not the original file). The default tpl.php file just spits out the content, but you can actually print out each line and nest them in divs so you can structure them easier, then you just need to apply css. All the field info should be stored in the $comment object. – Jance Feb 20 '14 at 16:01
  • Thanks, I really like your answers. I'll try to implement these things and accept your answer when I kind of succeeded to do so. – Jeroen Feb 20 '14 at 16:10

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.