<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body smarttemplateinserted="true" text="#000000" bgcolor="#FFFFFF">
Dear Vtiger Team,<br>
<br>
I am in the vtiger custom module development and there is an
interesting question:<br>
<br>
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.<br>
<br>
It is easy to manage with the following:<br>
(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)<br>
<br>
Vtiger_Event::register(<br>
'Contacts','vtiger.entity.aftersave',<br>
'ContactsHandler','modules/Contacts/ContactsHandler.php'<br>
);<br>
Vtiger_Event::register(<br>
'Contacts','vtiger.entity.beforesave',<br>
'ContactsHandler','modules/Contacts/ContactsHandler.php'<br>
);<br>
<br>
This action can be done during postinstall action of the Custom
module.<br>
<br>
And<br>
(2) Append the already existing
'modules/Contacts/ContactsHandler.php' file with the following
class:<br>
class ContactsHandler extends VTEventHandler {<br>
function handleEvent($eventName, $data) {<br>
if($eventName == 'vtiger.entity.beforesave') {<br>
// Entity is about to be saved, take required
action<br>
}<br>
if($eventName == 'vtiger.entity.aftersave') {<br>
// Entity has been saved, take next action<br>
}<br>
}<br>
} <br>
<br>
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.<br>
<br>
<b>The Question is:</b> To avoid modifying core files, will it work,
if I will put the custom Contacts handler into Custom module
directory?<br>
<br>
The step 1, registering the eventhandler file in an other place: <br>
Vtiger_Event::register(<br>
'Contacts','vtiger.entity.aftersave',<br>
'Contacts<b><font color="#cc0000">Custommodule</font></b>Handler','modules/<b><font
color="#cc0000">Custommodule</font></b>/Contacts<font
color="#cc0000"><b>Custommodule</b></font>Handler.php'<br>
);<br>
Vtiger_Event::register(<br>
'Contacts','vtiger.entity.beforesave',<br>
'Contacts<b><font color="#cc0000">Custommodule</font></b>Handler','modules/<font
color="#cc0000"><b>Custommodule</b></font>/Contacts<font
color="#cc0000"><b>Custommodule</b></font>Handler.php'<br>
);<br>
<br>
The step 2, create a handler file in the Custommodule directory:<br>
<br>
modules/<font color="#cc0000"><b>Custommodule</b></font>/Contacts<font
color="#cc0000"><b>Custommodule</b></font>Handler.php<br>
<?php class Contacts<b><font color="#cc0000">Custommodule</font></b>Handler
extends VTEventHandler {<br>
function handleEvent($eventName, $data) {<br>
if($eventName == 'vtiger.entity.beforesave') {<br>
// Entity is about to be saved, take required
action<br>
<font color="#cc0000"> // Some code to handle
Contacts related actions in the related module.</font><br>
}<br>
if($eventName == 'vtiger.entity.aftersave') {<br>
// Entity has been saved, take next action<br>
<font color="#cc0000"> // Some code to handle
Contacts related actions in the related module.</font><br>
}<br>
}<br>
} <br>
?><br>
<br>
Summary: Can I register an event handler with any name in any place?<br>
Will it triggered on a proper time?<br>
<br>
Kindest regards:<br>
István<br>
<br>
<div class="moz-signature">-- <br>
üdvözlettel:<br>
<br>
<b>Holbok István</b><br>
<br>
+3670-342-0900<br>
<b>e-mail:</b> <a class="moz-txt-link-abbreviated" href="mailto:holbok@gmail.com">holbok@gmail.com</a><br>
<b>SkyPe:</b> holboki<br>
<br>
</div>
</body>
</html>