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.


  1. int $commentId

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

  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.


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

use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;
use Contao\Comments;

class AddCommentListener
    public function __invoke(int $commentId, array $commentData, Comments $comments): void
        // Do something …