Module EventΒΆ
To register an event for a module, use the following:
include_once('vtlib/Vtiger/Event.php');
Vtiger_Event::register('<MODULENAME>', '<EVENTNAME>', '<HANDLERCLASS>', '<HANDLERFILE>');
<MODULENAME> |
Module for which events should be registered |
<EVENTNAME> |
vtiger.entity.aftersave, vtiger.entity.beforesave |
<HANDLERCLASS> |
Event handler class, look at the example below |
<HANDLERFILE> |
File where HANDLERCLASS is defined (should be within vtiger CRM directory) |
Example
Registering event callback before and after save.
if(Vtiger_Event::hasSupport()) {
Vtiger_Event::register(
'Payslip', 'vtiger.entity.aftersave',
'PayslipHandler', 'modules/Payslip/PayslipHandler.php'
);
Vtiger_Event::register(
'Payslip', 'vtiger.entity.beforesave',
'PayslipHandler', 'modules/Payslip/PayslipHandler.php'
);
}
modules/Payslip/PayslipHandler.php
<?php
class PayslipHandler extends VTEventHandler {
function handleEvent($eventName, $data) {
if($eventName == 'vtiger.entity.beforesave') {
// Entity is about to be saved, take required action
}
if($eventName == 'vtiger.entity.aftersave') {
// Entity has been saved, take next action
}
}
}
?>