Notifications are used to inform one or a given set of users about a specific event in your network as the liking of a post or mentioning of a user over multiple channels (e.g. web and mail).
Custom notification classes are derived from
humhub\modules\notification\components\BaseNotification|BaseNotification usually is assigned with an
$originator user instance and a
$source instance, which connects the Notification with a Content or any other kind of yii\db\ActiveRecord.
A Notification can be sent to a user by calling the
sendBulk() function. This will persist an
humhub\modules\notification\models\Notification instance for each user and send out a notification to all allowed
Since HumHub v1.3 Notifications are sent by means of a queued job.
Examples for core notifications are:
humhub\modules\like\notifications\NewLike: is sent if an user likes a post or comment.
humhub\modules\user\notifications\Followed: is sent if an user follows another user.
humhub\modules\user\notifications\Mentioned: is sent if an user is mentioned within an post or comment.
humhub\modules\content\notifications\ContentCreated: is sent when content (e.g. a post) was created.
Note: Unlike Activities which are targeted for multiple users e.g. all Users of a Space, a Notification is always targeted to a single user.
Custom Notifications are derived from
humhub\modules\notification\components\BaseNotification|BaseNotification]] and should reside in the notifications` directory of your module.
The notification class at least has to overwrite the
$moduleId variable with the id of your module and the.
By default, the view of a notification should be located inside
The view of the example above should therefore be located in
Info: If you require a different notification view for mails, you have to add an extra view file to
After an event was triggered, you'll have to instantiate your custom
BaseNotification and call its
A notification can optionally be assigned with a
$source model instance (e.g. a post or comment related to the notification) which has to be derived from yii\db\ActiveRecord.
Since HumHub v1.3 you have to overwrite
BaseNotification::requireSource in case your notification does not require an
source, otherwise they won't be sent out.
sendBulkwill create and persist a
humhub\modules\notification\models\Notificationinstance for each user.
Tip: Notifications are often created and sent within the
afterSavehook of the related
sourceinstance. This should be prefered over the instantiation within a controller.
Note: Notifications are only sent to a specific NotificationTarget depending on the user's account settings.
Sometimes you want to remove or replace notifications of a specific type. You can delete notifications similary to its creation syntax: