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.
int $commentId
ID of the new comment database record (Table tl_comments
).
array $commentData
Data of the new comment record (not including the ID).
\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;
#[AsHook('addComment')]
class AddCommentListener
{
public function __invoke(int $commentId, array $commentData, Comments $comments): void
{
// Do something …
}
}