0

I am working on a classifieds site where individual users can sign up and, of course, post things they would like to sell.

However, I need for users, both anonymous and signed up, to be able to contact the poster about his or her item.

Using the default comment form for this would be perfect. What would I need to do in order to allow only the author of that node to see the comments for his node? I don't mind writing a module if I need to, but I am not sure how to get started. Even if I had to go that route, sounds like I would need to modify the permissions setting?

I know there are other modules out there like Private Message, but that's just too big and bulky when Comments work almost exactly like I need them to.

Thanks!

1

So you want to use the comment form to do something other than leave comments on an article? That's pretty much the sole reason the comment form exists.

The core Contact module allows you to enable contact forms for every user on a site which, when used, send the message as an email to the corresponding user. I suggest you enable that module, then use something like hook_node_view() to add the contact form for the node author to the bottom of a node when it's displayed. I think that approach makes a good deal more sense than trying to use the comment form to do something it's not intended to do.

  • hmm I did not know that I could extract that contact form from the user's page and add it to the bottom of their nodes. That does sound like a better solution, if that is indeed what you are describing. Are there any functions in the API that specifically call the contact form? Do you have any sample code or any links to tutorials that may have used this technique? – blue928 Jun 7 '12 at 13:15
  • contact_personal_form() is the function that defines the user contact form, and it's in modules/contact/contact.pages.inc. You should be able to grab it using something like drupal_get_form('contact_personal_form', $account) where $account is the user object of the node author. Sorry, I don't know any sample code or tutorials for doing exactly this, but if you're already familiar with Drupal coding, that should be plenty to get you on the right track. (If you're not, then this might be a bit tough…) – Garrett Albright Jun 7 '12 at 13:22
1

I see some potential pitfalls with this approach:

  1. It probably won't be quite as simple as you describe because I guess you'd also like commenters to be able to see their comments, and replies to their comments, while hiding other people's comments. (Or am I wrong?)
  2. You mention you'd like to allow anon users to comment, so you need some way to differentiate one anon user from another (if they're able to see their own comments, but not others).
  3. It won't play nicely with page caching (at least without a bit of effort).
  4. It might make life a bit more difficult if you want to have normal comments on a content type at some point. (Eg. should the comment moderation tools be showing comments which are actually private messages?)

If you do want to go down this route however you can use hook_node_view_alter().

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.