Overview
This is an overview of how to create a module loadable package that will install a logic hook.
This example will install a sample logic hook to the accounts module that will default the account name to ‘My New Account Name ({time stamp})’. The full package is downloadable here for your reference.
For more details on the $manifest or $installdef options, you can visit the ‘Intorduction to the Manifest.
Manifest Example
<?php
$manifest = array(
'acceptable_sugar_flavors' => array('CE','PRO','CORP','ENT','ULT'),
'acceptable_sugar_versions' => array(
'exact_matches' => array(),
'regex_matches' => array('6\\.[0-9]\\.[0-9]),
),
'author' => 'SugarCRM',
'description' => 'Installs a sample logic hook',
'icon' => '',
'is_uninstallable' => true,
'name' => 'Example Logic Hook Installer',
'published_date' => '2012-07-06 2012 20:45:04',
'type' => 'module',
'version' => '1341607504',
);
$installdefs = array(
'id' => 'package_1341607504',
'copy' => array(
0 => array(
'from' => '<basepath>/Files/custom/modules/Accounts/accounts_save.php',
'to' => 'custom/modules/Accounts/accounts_save.php',
),
),
'logic_hooks' => array(
array(
'module' => 'Accounts',
'hook' => 'before_save',
'order' => 99,
'description' => 'Example Logic Hook - Updates account name',
'file' => 'custom/modules/Accounts/accounts_save.php',
'class' => 'Accounts_Save',
'function' => 'updateAccountName',
),
),
);
?>
Logic Hook Example
<?php
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class Accounts_Save
{
function updateAccountName($bean, $event, $arguments)
{
$bean->name = "My New Account Name (" . time() . ")";
}
}
?>