Comments functionality questions
Created 8 months ago by emergingdzns

I'm working on integrating the comments module on a module I've built. I need to find out if the following are possible with the module as it is now or do I have to extend it?

  1. Would like to be able to query comment count on a subject. I just want to be able to have it say something like "5 Comments" on a list page for the subject, but not the full comment list and form.
  2. Would like to override the gravatar image to use an image the user will be asked to update in their account using our module.
  3. Would like to include the comment form on the subject full details page by using {% include "anomaly.module.comments::comments" with {'subject': item} %} BUT also wanting to tell it to auto approve the comment for all users. We want to skip all moderation for now.


ryanthompson  —  8 months ago Best Answer

This is all certainly doable!

1.) Something like {{ subject.discussion.comments().count() }} should do it (note comments() and not comments the prior returns a relation the latter returns a collection).

2.) You can override all the views as needed:

3.) You can specify default approval state from the view as well just pass in 'approved': true along with the subject.

emergingdzns  —  8 months ago

You rock Ryan. Thanks!

emergingdzns  —  8 months ago

Ok so one more question... Is there any api functionality here where I can create my own form layout and submit the comment without using the comment form builder? My client wants a comment field that is more like the Facebook setup where it's a single line entry but we'd be using the bootstrap input-group to have the text field and button in one row. So I'm sure I need to custom build this but I need to know how to submit the comment, ideally via ajax call. Or would I need to have a controller in my own module that uses the discussion and comment repositories/models and inject it manually?

emergingdzns  —  8 months ago

I have partially answered my own question there. I realized I could do set form = form('comments')....get() etc and then make the form the way I want it 😄. However I would love to know if there's a way to submit it via AJAX instead of reloading the page.