SugarCRM is a very nice and open source CRM (Customer relationship management) system. And with being open source means that you are able to alter the internals of it and also are able to write modules for it easier than closed source applications because you can follow the direction of things if you are for example debugging etc.
The hooks part of the sugarCRM setup allows to place your own code into the base code at set parts of execution e.g. after retrieve of data, or post processing of data updates.
Here is a link to the sugarcrm site of hooks definitions. Basically there is 3 main types, with subhooks attached to those types.
- Application hooks
- after_ui_frame – Fired after the frame has been invoked and before the footer has been invoked
- after_ui_footer – Fired after the footer has been invoked
- server_round_trip – Fired at the end of every SugarCRM page
- Module hooks
- before_delete – Fired before a record is deleted
- after_delete – Fired after a record is deleted
- before_restore – Fired before a record is undeleted
- after_restore – Fired after a record is undeleted
- after_retrieve – Fired after a record has been retrieved from the database. This hook does not fire when you create a new record.
- before_save – Fired before a record is saved.
- after_save – Fired after a record is saved.
- process_record – Fired immediately prior to the database query resulting in a record being made current. This gives developers an opportunity to examine and tailor the underlying queries. This is also a perfect place to set values in a record’s fields prior to display in the DetailView or ListView. This event is not fired in the EditView.
- Users
- before_logout – Fired before a user logs out of the system
- after_logout – Fired after a user logs out of the system
- after_login – Fired after a user logs into the system.
- after_logout – Fired after a user logs out of the system.
- before_logout – Fired before a user logs out of the system.
- login_failed – Fired on a failed login attempt
What I have done below is to use a module hook for the after_retrieve method.
If you save this
<?php $hook_version = 1; $hook_array = Array(); $hook_array['after_retrieve'] = Array(); $hook_array['after_retrieve'][] = Array(1, 'after_retrieve', 'custom/modules/Users/users_after_retrieve.php','users_after_retrieve_class', 'users_after_retrieve_method'); ?>
In the
The hook array denotes the hooks to add into the module execution and you first create a array and then another array for the ‘after_retrieve’ functions to be called. The third array structure is version, event, php file, class name, method to call.
And here is the php file for the above hook, called users_after_retrieve.php
<?php class users_after_retrieve_class { function users_after_retrieve_method(&$bean, $event, $arguments=null) { // print_r($bean); // to get the full details of the bean // make sure we are doing a after_retrieve event if ($event != 'after_retrieve') return; $bean->description = "The best thing in the world is being a dad, it really is"; } } ?>
The output of this, you will have to goto the Users in the Admin area
