Events can be used to extend the functionality of Comments.
beforeSaveComment
event#Plugins can get notified before a comment is saved. Event handlers can prevent the comment from getting sent by setting $event->isValid
to false.
use craft\events\ModelEvent;
use verbb\comments\elements\Comment;
use yii\base\Event;
Event::on(Comment::class, Comment::EVENT_BEFORE_SAVE, function(ModelEvent $event) {
$comment = $event->sender;
$event->isValid = false;
});
afterSaveComment
event#Plugins can get notified after a comment has been saved
use craft\events\ModelEvent;
use verbb\comments\elements\Comment;
use yii\base\Event;
Event::on(Comment::class, Comment::EVENT_AFTER_SAVE, function(ModelEvent $event) {
$comment = $event->sender;
});
beforeSaveFlag
event#Plugins can get notified before a flag is saved
use verbb\comments\events\FlagEvent;
use verbb\comments\services\Flags;
use yii\base\Event;
Event::on(Flags::class, Flags::EVENT_BEFORE_SAVE_FLAG, function(FlagEvent $event) {
// Do something
});
afterSaveFlag
event#Plugins can get notified after a flag has been saved
use verbb\comments\events\FlagEvent;
use verbb\comments\services\Flags;
use yii\base\Event;
Event::on(Flags::class, Flags::EVENT_AFTER_SAVE_FLAG, function(FlagEvent $event) {
// Do something
});
beforeDeleteFlag
event#Plugins can get notified before an flag is deleted
use verbb\comments\events\FlagEvent;
use verbb\comments\services\Flags;
use yii\base\Event;
Event::on(Flags::class, Flags::EVENT_BEFORE_DELETE_FLAG, function(FlagEvent $event) {
// Do something
});
afterDeleteFlag
event#Plugins can get notified after a flag has been deleted
use verbb\comments\events\FlagEvent;
use verbb\comments\services\Flags;
use yii\base\Event;
Event::on(Flags::class, Flags::EVENT_AFTER_DELETE_FLAG, function(FlagEvent $event) {
// Do something
});
beforeSaveVote
event#Plugins can get notified before a vote is saved
use verbb\comments\events\VoteEvent;
use verbb\comments\services\Votes;
use yii\base\Event;
Event::on(Votes::class, Votes::EVENT_BEFORE_SAVE_VOTE, function(VoteEvent $event) {
// Do something
});
afterSaveVote
event#Plugins can get notified after a vote has been saved
use verbb\comments\events\VoteEvent;
use verbb\comments\services\Votes;
use yii\base\Event;
Event::on(Votes::class, Votes::EVENT_AFTER_SAVE_VOTE, function(VoteEvent $event) {
// Do something
});
beforeDeleteVote
event#Plugins can get notified before a vote is deleted
use verbb\comments\events\VoteEvent;
use verbb\comments\services\Votes;
use yii\base\Event;
Event::on(Votes::class, Votes::EVENT_BEFORE_DELETE_VOTE, function(VoteEvent $event) {
// Do something
});
afterDeleteVote
event#Plugins can get notified after a vote has been deleted
use verbb\comments\events\VoteEvent;
use verbb\comments\services\Votes;
use yii\base\Event;
Event::on(Votes::class, Votes::EVENT_AFTER_DELETE_VOTE, function(VoteEvent $event) {
// Do something
});
beforeSendAuthorEmail
event#Plugins can get notified before the author's email is sent
use verbb\comments\events\EmailEvent;
use verbb\comments\services\Comments as CommentsService;
use yii\base\Event;
Event::on(CommentsService::class, CommentsService::EVENT_BEFORE_SEND_AUTHOR_EMAIL, function(EmailEvent $event) {
// Prevent sending
$event->isValid = false;
});
beforeSendReplyEmail
event#Plugins can get notified before a reply email is sent
use verbb\comments\events\EmailEvent;
use verbb\comments\services\Comments as CommentsService;
use yii\base\Event;
Event::on(CommentsService::class, CommentsService::EVENT_BEFORE_SEND_REPLY_EMAIL, function(EmailEvent $event) {
// Prevent sending
$event->isValid = false;
});
beforeSendModeratorEmail
event#Plugins can get notified before each moderator's email is sent
use verbb\comments\events\EmailEvent;
use verbb\comments\services\Comments as CommentsService;
use yii\base\Event;
Event::on(CommentsService::class, CommentsService::EVENT_BEFORE_SEND_MODERATOR_EMAIL, function(EmailEvent $event) {
// Prevent sending
$event->isValid = false;
});
beforeSendModeratorApprovedEmail
event#Plugins can get notified before the moderator approved email is sent
use verbb\comments\events\EmailEvent;
use verbb\comments\services\Comments as CommentsService;
use yii\base\Event;
Event::on(CommentsService::class, CommentsService::EVENT_BEFORE_SEND_MODERATOR_APPROVED_EMAIL, function(EmailEvent $event) {
// Prevent sending
$event->isValid = false;
});
beforeSendSubscribeEmail
event#Plugins can get notified before a subscribed element's email is sent. This is the email that is sent to all subscribers of an element, when a comment is made.
use verbb\comments\events\EmailEvent;
use verbb\comments\services\Comments as CommentsService;
use yii\base\Event;
Event::on(CommentsService::class, CommentsService::EVENT_BEFORE_SEND_SUBSCRIBE_EMAIL, function(EmailEvent $event) {
// Prevent sending
$event->isValid = false;
});
beforeSendAdminEmail
event#Plugins can get notified before the admin email is sent
use verbb\comments\events\EmailEvent;
use verbb\comments\services\Comments as CommentsService;
use yii\base\Event;
Event::on(CommentsService::class, CommentsService::EVENT_BEFORE_SEND_ADMIN_EMAIL, function(EmailEvent $event) {
// Prevent sending
$event->isValid = false;
});