Events can be used to extend the functionality of Wishlist.
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 craft\events\ModelEvent;
use verbb\wishlist\elements\ListElement;
use yii\base\Event;
Event::on(ListElement::class, ListElement::EVENT_BEFORE_SAVE, function(ModelEvent $event) {
$list = $event->sender;
$event->isValid = false;
});
afterSaveList
event#Plugins can get notified after a list has been saved
use craft\events\ModelEvent;
use verbb\wishlist\elements\ListElement;
use yii\base\Event;
Event::on(ListElement::class, ListElement::EVENT_AFTER_SAVE, function(ModelEvent $event) {
$list = $event->sender;
});
beforeDeleteList
event#Plugins can get notified before a list is deleted. 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_DELETE, function(Event $event) {
$list = $event->sender;
$event->isValid = false;
});
afterDeleteList
event#Plugins can get notified after a list has been deleted
use verbb\wishlist\elements\ListElement;
use yii\base\Event;
Event::on(ListElement::class, ListElement::EVENT_AFTER_DELETE, function(Event $event) {
$list = $event->sender;
});
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 $event) {
// Maybe create an audit trail of this action.
});
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 $event) {
// Maybe prepare some third party system for a new list type
});
beforeSaveItem
event#Plugins can get notified before an item is saved. Event handlers can prevent the item from getting sent by setting $event->isValid
to false.
use craft\events\ModelEvent;
use verbb\wishlist\elements\Item;
use yii\base\Event;
Event::on(Item::class, Item::EVENT_BEFORE_SAVE, function(ModelEvent $event) {
$item = $event->sender;
$event->isValid = false;
});
afterSaveItem
event#Plugins can get notified after an item has been saved
use craft\events\ModelEvent;
use verbb\wishlist\elements\Item;
use yii\base\Event;
Event::on(Item::class, Item::EVENT_AFTER_SAVE, function(ModelEvent $event) {
$item = $event->sender;
});
beforeDeleteItem
event#Plugins can get notified before an item is deleted. 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_DELETE, function(Event $event) {
$item = $event->sender;
$event->isValid = false;
});
afterDeleteList
event#Plugins can get notified after a item has been deleted
use verbb\wishlist\elements\Item;
use yii\base\Event;
Event::on(Item::class, Item::EVENT_AFTER_DELETE, function(Event $event) {
$item = $event->sender;
});