[Vtigercrm-developers] [2.] What is the best practice to create Extensions Store compatible vtiger 6.1 custom module?

Holbok István holbok at gmail.com
Mon Jul 14 10:13:10 GMT 2014


Dear Vtiger Team,

*Tested. It works:*

To avoid modifying core files, we can take place the custom Contacts 
handler into the Custom module director.

*The step 1, registering the eventhandler file in an other place: *
$moduleInstance = Vtiger_Module::getInstance('Contacts');
Vtiger_Event::register(
      $moduleInstance, 'vtiger.entity.aftersave',
     
  'Contacts*Custommodule*Handler','modules/*Custommodule*/Contacts*Custommodule*Handler.php'
);
Vtiger_Event::register(
     $moduleInstance, 'vtiger.entity.beforesave',
     
'Contacts*Custommodule*Handler','modules/*Custommodule*/Contacts*Custommodule*Handler.php'
);

*(Here is the small change in th Step 1: You should use the Contacts 
module instance instead of the plain module name.)
*
*The step 2, create a handler file in the Custommodule directory:*

modules/*Custommodule*/Contacts*Custommodule*Handler.php
<?php class Contacts*Custommodule*Handler extends VTEventHandler {
      function handleEvent($eventName, $data) {
              if($eventName == 'vtiger.entity.beforesave') {
                      // Entity is about to be saved, take required action
// Some code to handle Contacts related actions in the related module.
              }
              if($eventName == 'vtiger.entity.aftersave') {
                      // Entity has been saved, take next action
// Some code to handle Contacts related actions in the related module.
              }
      }
}
?>

Summary: We can register an event handler with any name in any place. 
And it will trigger the "vtiger.entity.beforesave" and the 
"vtiger.entity.aftersave" events also.
You do not need to change core files to catch an event e.g. from 
Contacts, Leads or other modules.


Kindest regards:
István

-- 
üdvözlettel:

*Holbok István*

+3670-342-0900
*e-mail:* holbok at gmail.com
*SkyPe:* holboki

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20140714/3b1dfc34/attachment.html>


More information about the vtigercrm-developers mailing list