Optional Step: Module Events
To register an event for a module, use the following:
include_once('vtlib/Vtecrm/Event.php');
Vtecrm_Event::register('<MODULENAME>', '<EVENTNAME>',
'<HANDLERCLASS>', '<HANDLERFILE>');
<MODULNAME> //Module for which events should be registered
<EVENTNAME> //vtiger.entity.aftersave //vtiger.entity.beforesave
<HANDLERCLASS> //Event handler class, look at the example below
<HANDLERFILE> //File where HANDLERCLASS is defined (should be within vtiger CRM directory)
Example: Registering event callback before and after save.
if(Vtecrm_Event::hasSupport()) {
Vtecrm_Event::register(
'InstalledBase', 'vtecrm.entity.aftersave',
'InstalledBaseHandler', 'modules/InstalledBase/InstalledBaseHandler.php'
);
Vtecrm_Event::register(
'InstalledBase', 'vtiger.entity.beforesave',
'InstalledBaseHandler', 'modules/InstalledBase/InstalledBaseHandler.php'
);
}
modules/InstalledBase/ InstalledBaseHandler.php
<?php
class InstalledBaseHandler extends VTEventHandler {
function handleEvent($eventName, $data) {
if($eventName == 'vtecrm.entity.beforesave') {
// Entity is about to be saved, take required action
}
if($eventName == 'vtecrm.entity.aftersave') {
// Entity has been saved, take next action
}
}
}
?>
Optional Step: Module Templates
If you would like to customize the list view or have a custom Settings page for the module, then you will need to create a Smarty template accordingly. You will need to have some knowledge of Smarty templates usage before you proceed.
Your module specific Smarty template files should be created under
Smarty/templates/modules/<newmodulename>.</newmodulename>
Use vtlib_getModuleTemplate($module, $templateName) API (include/utils/VtlibUtils.php) as:
$smarty->display(vtlib_getModuleTemplate($currentModule, 'MyListview.tpl'));
Optional Step: Custom Links
You can add custom web link to the module using the following API:
include_once('vtlib/Vtecrm/Module.php');
$moduleInstance = Vtecrm_Module::getInstance('ModuleName');
$moduleInstance->addLink(<LinkType>, <LinkLabel>, <LinkURL>);
LinkType //Type of Link like DETAILVIEW etc..
LinkLabel //Label to use for the link when displaying
LinkURL //URL of the link. You can use variables like $variablename$
Given below is an example which adds a link to the DetailView of the Module.
include_once('vtlib/Vtecrm/Module.php');
$moduleInstance = Vtecrm_Module::getInstance('InstalledBase');
$moduleInstance->addLink(
'DETAILVIEW',
'New Action',
'index.php?module=OtherModule&action=SomeAction&src_module=$MODULE$&src_record=$RECORD$'
);
NOTE: The $MODULE$ and $RECORD$ variables for the 'New Action' link will be replaced with the values set through DetailView.php
Special LinkType
Following LinkTypes are treated specially while processing for display:
| Linktype | Description |
|---|---|
| HEADERSCRIPT | The link will be treated as a javascript type and will be imported in the head section of the HTML output page as <script type="text/javascript" src="linkurl"></script> |
| HEADERCSS | The link will be treated as a CSS type and will be imported in the head section of the HTML output page as |