Home
Github
Wiki
Videos
Contact
Sponsor
Registering Event Handlers
you can subscribe to various puck events. to hook into the content indexer (for Lucene indexing) before and after index events, you need to first get the indexer. the `puck.core.State.PuckCache` class has a singleton property accessor which you can use to get the indexer which is useful when injecting it into a controller is not possible (i.e. on app startup). ```cs PuckCache.PuckIndexer.RegisterAfterIndexHandler
("puck_publish_notification", (object o, puck.core.Events.IndexingEventArgs args) => { },Propagate:true); ``` here we are subscribing to `AfterIndex` event for the `BaseModel` ViewModel but since the `Propagate` argument is set to true, it will trigger for any ViewModel which can be assigned to BaseModel (which is all ViewModels, since they all inherit from `BaseModel`). `IndexingEventArgs` will contain the ViewModel being indexed. in a similar way, you can also register event handlers for `puck.core.Services.ContentService`: `ContentService.RegisterAfterSaveHandler
()`, `ContentService.RegisterBeforeSaveHandler
()`, `ContentService.RegisterAfterDeleteHandler
`, `ContentService.RegisterBeforeDeleteHandler
`, `ContentService.RegisterBeforeMoveHandler`, `ContentService.RegisterAfterMoveHandler
`. there is also the `ContentService.AfterCreate` event which can be used to set default values on newly created content. note that the "BeforeSave" and "BeforeIndex" events use `BeforeIndexingEventArgs` (which allows you to cancel the saving/indexing) and "AfterSave" and "AfterIndex" events use `IndexingEventArgs`. the move events use `BeforeMoveEventArgs` and `MoveEventArgs`. there is also the `puck.core.Helpers.ApiHelper.AfterEditorSettingsSave` event to hook into editor parameter save event and the `puck.core.Helpers.SyncHelper.AfterSync` event to subscribe to sync event for load balanced environments when servers are synchronizing content.