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

<?php namespace Craft;  class SproutEmailEvents_BeforeSaveEntryEvent extends SproutEmailBaseEvent {   /**    * Returns the qualified event name to use when registering with craft()->on    *     * @return string    */   public function getName()   {     return 'entries.onBeforeSaveEntry';   }      /**    * Returns the event title to use when displaying a label or similar use case    *    * @return string    */   public function getTitle()   {     return Craft::t('Before an entry is saved');   }    /**    * Returns a short description of this event    *    * @return string    */   public function getDescription()   {     return Craft::t('Triggers before an entry is saved.');   }      /**    * Validate your Event options    *    * @return bool    */   public function validateOptions()   {     return true;   }      /**    * Returns the data passed in by the triggered event    *    * @param Event $event    *    * @return mixed    */   public function prepareParams(Event $event)   {     return array(       'value'      => array(         $event->params['entry'],         'isNewEntry' => $event->params['isNewEntry']       )        );   } } 
  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.

/**  * Defines events/rules for notification entries in Sprout Email  *  * @return array  */ public function defineSproutEmailEvents() {   Craft::import('plugins.sproutemailevents.integrations.sproutemail.SproutEmailEvents_BeforeSaveEntryEvent');      return array(     'entries.onBeforeSaveEntry' => new SproutEmailEvents_BeforeSaveEntryEvent()   ); }