You need two files, the first is the definition of the hook and the second contains the actual code to be executed.
Here is an example that will proper case the Last Name field of the Contacts module. To use it, create a file named logic_hooks.php with the following content and put it in the <sugar>/custom/modules/Contacts folder (create folder if necessary):
Code:
<?php
$hook_version = 1;
$hook_array = Array();
$hook_array['before_save'][] = Array(1, 'ProperTest', 'custom/modules/Contacts/proper_case.php', 'ProperText', 'convertToProper');
?>
Next, create another PHP file with the following contents and name it proper_case.php and place it in the same folder as where logic_hooks exists:
Code:
<?php
/*************************************
Project: Sample Hook to Proper Case a Field's Value
Original Dev: Angel Magaņa, February 2010
cheleguanaco[at]gmail.com
Desc: Logic Hook Code for Proper Case Update
The contents of this file are governed by the GNU General Public License (GPL).
A copy of said license is available here: http://www.gnu.org/copyleft/gpl.html
This code is provided AS IS and WITHOUT WARRANTY OF ANY KIND.
*************************************/
class ProperText {
function convertToProper(&$bean, $event, $arguments)
{
$bean->last_name = ucwords($bean->last_name);
}
}
?> That should do it. Add a contact via the Create Contact link and make sure that proper casing is applied to the Last Name field after you save it.
Bookmarks