addComment

The addComment hook is triggered when a comment is added. It passes the ID of the record and the data array as arguments and does not expect a return value.

Parameters

  1. int $commentId

    ID of the new comment database record (Table tl_comment).

  2. array $commentData

    Data of the new comment record (not including the ID).

  3. \Contao\Comments $comments

    The instance of the \Contao\Comments class that triggered the hook.

Example

// src/EventListener/AddCommentListener.php
namespace App\EventListener;

use Contao\CoreBundle\ServiceAnnotation\Hook;
use Contao\Comments;
use Terminal42\ServiceAnnotationBundle\ServiceAnnotationInterface;

class AddCommentListener implements ServiceAnnotationInterface
{
    /**
     * @Hook("addComment")
     */
    public function onAddComment(int $commentId, array $commentData, Comments $comments): void
    {
        // Do something …
    }
}

References