Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding event handlers to extension modules
I was reading the vtlib docs and came accross this code:

<?xml version="1.0" encoding=”utf-8”?>
<label>MODULE LABEL</label>
<condition><![CDATA[modulename in ['MODULENAME']]]></condition>

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) {
$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?
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.
Great, thanks. That's what I thought but nice to know for sure.

Forum Jump:

Users browsing this thread: 1 Guest(s)