<div dir="ltr">Got impression that extension store will be interesting place to surf :-)<div><br></div><div>Andrew</div><div class="gmail_extra"><div><div dir="ltr"><div><br></div></div></div>
<br><br><div class="gmail_quote">On Mon, Jul 14, 2014 at 3:47 PM, Holbok István <span dir="ltr"><<a href="mailto:holbok@gmail.com" target="_blank">holbok@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div 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<span><font color="#888888"><br>
<br>
<div>-- <br>
üdvözlettel:<br>
<br>
<b>Holbok István</b><br>
<br>
+3670-342-0900<br>
<b>e-mail:</b> <a href="mailto:holbok@gmail.com" target="_blank">holbok@gmail.com</a><br>
<b>SkyPe:</b> holboki<br>
<br>
</div>
</font></span></div>
<br>_______________________________________________<br>
<a href="http://www.vtiger.com/" target="_blank">http://www.vtiger.com/</a><br></blockquote></div><br></div></div>