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

Vic Cekvenich vic.cvc at gmx.com
Sun Aug 17 22:00:09 GMT 2014



-------- Original Message --------
Subject: 	[Vtigercrm-developers] What is the best practice to create 
Extensions Store compatible vtiger 6.1 custom module?
Date: 	Mon, 14 Jul 2014 10:47:55 +0200
From: 	Holbok István <holbok at gmail.com>
Reply-To: 	holbok at gmail.com, vtigercrm-developers at lists.vtigercrm.com
To: 	vtigercrm-developers at lists.vtigercrm.com 
<vtigercrm-developers at lists.vtigercrm.com>



Dear Vtiger Team,

I am in the vtiger custom module development and there is an interesting 
question:

This Custom module is related to the (standard) Contacts module and when 
some fields were changed in the Contacts module record, accordingly some 
change should be done in the related Custom module record.

It is easy to manage with the following:
(1) Register an Eventhandler for the Contacts module (note: there is not 
any event registered for the Contacts module in the standard install of 
vtiger 6.1. SVN 14164)

Vtiger_Event::register(
      'Contacts','vtiger.entity.aftersave',
      'ContactsHandler','modules/Contacts/ContactsHandler.php'
);
Vtiger_Event::register(
     'Contacts','vtiger.entity.beforesave',
     'ContactsHandler','modules/Contacts/ContactsHandler.php'
);

This action can be done during postinstall action of the Custom module.

And
(2) Append the already existing 'modules/Contacts/ContactsHandler.php' 
file with the following class:
class ContactsHandler 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
              }
      }
}

This will work without any doubt but in this way I have to modify a core 
file: 'modules/Contacts/ContactsHandler.php' and it could make some 
troubles for the Estension Store Custom module.

*The Question is:* To avoid modifying core files, will it work, if I 
will put the custom Contacts handler into Custom module directory?

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

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: Can I register an event handler with any name in any place?
Will it triggered on a proper time?

Kindest regards:
István

-- 
üdvözlettel:

*Holbok István*

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

-------------- next part --------------
_______________________________________________
http://www.vtiger.com/


More information about the vtigercrm-developers mailing list