Events

Events can be used to extend the functionality of Wishlist.

List related events #

The beforeSaveList event #

Plugins can get notified before a list is saved. Event handlers can prevent the list from getting sent by setting $event->isValid to false.

use verbb\wishlist\elements\ListElement;
use yii\base\Event;

Event::on(ListElement::class, ListElement::EVENT_BEFORE_SAVE, function(Event $e) {
    $list = $event->sender;
    $event->isValid = false;
});

The afterSaveList event #

Plugins can get notified after a list has been saved

use verbb\wishlist\elements\ListElement;
use yii\base\Event;

Event::on(ListElement::class, ListElement::EVENT_AFTER_SAVE, function(Event $e) {
    $list = $event->sender;
});

The beforeSaveListType event #

Plugins can get notified before a list type is being saved.

use verbb\wishlist\events\ListTypeEvent;
use verbb\wishlist\services\ListTypes;
use yii\base\Event;

Event::on(ListTypes::class, ListTypes::EVENT_BEFORE_SAVE_LISTTYPE, function(ListTypeEvent $e) {
     // Maybe create an audit trail of this action.
});

The afterSaveListType event #

Plugins can get notified after a list type has been saved.

use verbb\wishlist\events\ListTypeEvent;
use verbb\wishlist\services\ListTypes;
use yii\base\Event;

Event::on(ListTypes::class, ListTypes::EVENT_AFTER_SAVE_LISTTYPE, function(ListTypeEvent $e) {
     // Maybe prepare some third party system for a new list type
});

Item related events #

The beforeSaveItem event #

Plugins can get notified before a item is saved. Event handlers can prevent the item from getting sent by setting $event->isValid to false.

use verbb\wishlist\elements\Item;
use yii\base\Event;

Event::on(Item::class, Item::EVENT_BEFORE_SAVE, function(Event $e) {
    $item = $event->sender;
    $event->isValid = false;
});

The afterSaveList event #

Plugins can get notified after a item has been saved

use verbb\wishlist\elements\Item;
use yii\base\Event;

Event::on(Item::class, Item::EVENT_AFTER_SAVE, function(Event $e) {
    $item = $event->sender;
});

Get started with Wishlist

Available for Craft 3 for $49