Creating an event handler in Blesta consists of merely filling in a stubbed callback method, or returning an array of callbacks from a plugin's getEvents() method. Blesta offers a number of events that are automatically triggered when needed. The default handlers for these events may be found in the /installdir/components/events/default/ directory. You can paste your event handler code directly into any of the default handler methods, or more preferably, create a plugin to handle the event.
Events
Event | Triggered When | Default Event Handler | Parameters | Returns | Since |
---|---|---|---|---|---|
Appcontroller.preAction | A URI is requested | EventsAppControllerCallback::preAction() | void | void | 3.0 |
Clients.create | A client is created | EventsClientsCallback::create() |
| void | 3.1 |
Emails.send | An email template is sent | EventsEmailsCallback::send() |
| array Key/value pairs to merge with tags. | 3.1 |
Emails.sendCustom | A non-template based email is sent | EventsEmailsCallback::sendCustom() |
| array Key/value pairs to merge with tags. | 3.1 |
Invoices.add | An invoice is created | EventsInvoicesCallback::add() |
| void | 3.1 |
Invoices.edit | An invoice is updated | EventsInvoicesCallback::edit() |
| void | 3.1 |
Invoices.setClosed | An invoice is closed | EventsInvoicesCallback::setClosed() |
| void | 3.1 |
Transactions.add | A transaction is created | EventsTransactionsCallback::add() |
| void | 3.1 |
Transactions.edit | A transaction is updated | EventsTransactionsCallback::edit() |
| void | 3.1 |
Users.login | A user logs in | EventsUsersCallback::login() |
| void | 3.1 |
Users.logout | A user logs out | EventsUsersCallback::logout() |
| void | 3.1 |
Navigation.getSearchOptions | Staff search options are displayed | EventsNavigationCallback::getSearchOptions() |
| void | 3.0 |
Working with Events
Each event handler that is invoked when the event is triggered is passed an EventObject. You can modify the parameters or return value of this object and the modified event will be passed along to each subsequent handler, and finally returned to the trigger.
To fetch parameters from the EventObject invoke the getParams() method. Similarly, to set parameters use the setParams() method.
To set the return value from the EventObject invoke the setReturnVal() method. Similarly, to fetch the return value use the getReturnVal() method.