Notification Events

You can trigger Notification Emails via custom Notification Events in your own plugins. A Notification Event tells Sprout Email to watch for a particular Event (in Craft or another plugin) and provides validation rules that will be checked to determine when a Notification Email should be triggered.

Adding custom events involves:

  1. Extending Sprout Email's Notification Event class
  2. Registering your Notification Event

Notification Event Class

namespace company\plugin\folder;  use barrelstrength\sproutbase\app\email\base\NotificationEvent;  class EntriesSave extends NotificationEvent {   ... } 

Craft 3

See the base NotificationEvent Class for documentation on usage:

Examples can be found in:

Craft 2

  1. Extend SproutEmailBaseEvent with your custom event
  2. Register your event using the defineSproutEmailEvents() hook

To demonstrate how to add a custom event via a plugin, we've created an example plugin that implements the Craft onBeforeSaveEntry Event: Sprout Email Events Plugin

Additional implementation examples can be seen in Sprout Email itself (sproutemail/integrations/sproutemail).

Register Event

To tell Sprout Email that your event exists you need to register it in your plugin's Primary Class file.

namespace mycompany\myplugin;  use mycompany\myplugin\integrations\sproutemail\events\notificationevents\MyNotificationEvent; use barrelstrength\sproutbase\app\email\services\NotificationEmailEvents; use barrelstrength\sproutbase\app\email\events\NotificationEmailEvent; use yii\base\Event;  class MyPlugin extends Plugin {    public function init()   {     parent::init();          Event::on(NotificationEmailEvents::class, NotificationEmailEvents::EVENT_REGISTER_EMAIL_EVENT_TYPES, function(NotificationEmailEvent $event) {         $event->events[] = MyNotificationEvent::class;     });      } }