CoreBOSBB
Adding event handlers to extension modules - Printable Version

+- CoreBOSBB (https://discussions.corebos.org)
+-- Forum: Development (https://discussions.corebos.org/forumdisplay.php?fid=18)
+--- Forum: coreBOS Development (https://discussions.corebos.org/forumdisplay.php?fid=4)
+--- Thread: Adding event handlers to extension modules (/showthread.php?tid=523)



Adding event handlers to extension modules - Guido1982 - 12-13-2016

I was reading the vtlib docs and came accross this code:

Code:
<?xml version="1.0" encoding=”utf-8”?>
<module>
<type>extension</type>
<name>MODULENAME</name>
<label>MODULE LABEL</label>
<parent>Tools</parent>
<version>1.0</version>
<dependencies>
<vtiger_version>5.1.0</vtiger_version>
</dependencies>
<tables>
<table>
<name>TABLE-NAME</name>
<sql><![CDATA[CREATE_TABLE_SQL]]></sql>
</table>
</tables>
<events>
<event>
<eventname>EVENT_NAME</eventname>
<classname>EVENT_HANDLER_CLASS</classname>
<filename>EVENT_HANDLER_CLASS_FILE</filename>
<condition><![CDATA[modulename in ['MODULENAME']]]></condition>
</event>
</events>
</module>

Where I see you can add event handlers in the manifest file of an extension module. But we could just as easily do it in the vtlib_handler class method of the main file right? So in modules/MyModuleName/MyModuleName.php I would create:

PHP Code:
    function vtlib_handler($modulename$event_type) {
        if(
$event_type == 'module.postinstall') {
            
// TODO Handle post installation actions
        
} else if($event_type == 'module.disabled') {
            
// TODO Handle actions when this module is disabled.
        
} else if($event_type == 'module.enabled') {
            
// TODO Handle actions when this module is enabled.
        
} else if($event_type == 'module.preuninstall') {
            
// TODO Handle actions when this module is about to be deleted.
        
} else if($event_type == 'module.preupdate') {
            
// TODO Handle actions before this module is updated.
        
} else if($event_type == 'module.postupdate') {
            
// TODO Handle actions after this module is updated.
        
}
    } 

Where I would do the event handler creation in the postinstall?


RE: Adding event handlers to extension modules - joebordes - 12-13-2016

Creating the event handler in the manifest file is equivalent to creating it in the vtlib_handler postinstall section. The manifest file gets executed on install of the module/extension and then the vtlib_handler postinstall section is invoked. So they are basically the same. The big difference is that vtlib_handler you can execute any code you want.


RE: Adding event handlers to extension modules - Guido1982 - 12-13-2016

Great, thanks. That's what I thought but nice to know for sure.