Skip to content
reillyethan edited this page Feb 16, 2015 · 12 revisions

Comment module is used (obviously) for commenting specific entities. Let's look how it works.

Test how it works

  • Open your app in browser and go to dashboard
  • Choose Comment -> Write Comments.

Is it possible to comment comments?

Yes, but this is disabled by default (for a lot of reasons). To enable this feature:

  • Go to a dashboardand choose Comment -> Create entity
  • Create an entity with alias comment and choose Comment\Entity\Comment. Also mark all fields checked to enable visibility and possibility to comment. From this moment all your comments will have a button Answer, try it!

How to comment custom made Entity?

  1. Go to a dashboard Comment -> Create entity and create an entity based on your custom made one. So you need to give it an alias and choose it from the list of entities. Then mark needed options as checked.
  2. Create an object of your Entity (e.g. add a new row to a table in your db).
  3. Create a controller for displaying this entity, and pass it to a viewmodel with Comment\Service\Comment
$commentService = $this->getServiceLocator()->get('Comment\Service\Comment'); 

3.1 Also, pass to a view an array of comments using this service

$comments = $commentService->treeByEntity($entity); //$entity is an object of your entity

3.2 Then we need to check if comments are visible for your $entityType. You must get

$entityType->isVisible()
  1. In a view somehow display this entity (if you want, of course) and generate a form for entering comments using method from $commentService:
$commentService->getAddCommentForm($commentService->createForm(), $entityId, $entityAlias);
  1. Display comments using view helper
   if ($comments && is_array($comments) && count($comments)) {
       echo $this->comment($comments);
   };

That's all, pretty simple, ha!

Clone this wiki locally