3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
30 * @package CiviCRM_Hook
31 * @copyright CiviCRM LLC (c) 2004-2014
36 abstract class CRM_Utils_Hook
{
38 // Allowed values for dashboard hook content placement
39 // Default - place content below activity list
40 CONST DASHBOARD_BELOW
= 1;
41 // Place content above activity list
42 CONST DASHBOARD_ABOVE
= 2;
43 // Don't display activity list at all
44 CONST DASHBOARD_REPLACE
= 3;
46 // by default - place content below existing content
47 CONST SUMMARY_BELOW
= 1;
48 // pace hook content above
49 CONST SUMMARY_ABOVE
= 2;
50 // create your own summarys
51 CONST SUMMARY_REPLACE
= 3;
53 static $_nullObject = NULL;
56 * We only need one instance of this object. So we use the singleton
57 * pattern and cache the instance in this variable
62 static private $_singleton = NULL;
67 private $commonIncluded = FALSE;
72 private $commonCiviModules = array();
75 * Constructor and getter for the singleton instance
80 * An instance of $config->userHookClass
82 static function singleton($fresh = FALSE) {
83 if (self
::$_singleton == NULL ||
$fresh) {
84 $config = CRM_Core_Config
::singleton();
85 $class = $config->userHookClass
;
86 require_once (str_replace('_', DIRECTORY_SEPARATOR
, $config->userHookClass
) . '.php');
87 self
::$_singleton = new $class();
89 return self
::$_singleton;
95 * @param int $numParams Number of parameters to pass to the hook
96 * @param mixed $arg1 parameter to be passed to the hook
97 * @param mixed $arg2 parameter to be passed to the hook
98 * @param mixed $arg3 parameter to be passed to the hook
99 * @param mixed $arg4 parameter to be passed to the hook
100 * @param mixed $arg5 parameter to be passed to the hook
101 * @param mixed $arg6 parameter to be passed to the hook
102 * @param string $fnSuffix function suffix, this is effectively the hook name
106 abstract function invoke($numParams,
107 &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6,
111 function commonInvoke($numParams,
112 &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6,
116 $this->commonBuildModuleList($fnPrefix);
118 return $this->runHooks($this->commonCiviModules
, $fnSuffix,
119 $numParams, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6
124 * Build the list of modules to be processed for hooks.
126 * @param string $fnPrefix
128 function commonBuildModuleList($fnPrefix) {
129 if (!$this->commonIncluded
) {
130 // include external file
131 $this->commonIncluded
= TRUE;
133 $config = CRM_Core_Config
::singleton();
134 if (!empty($config->customPHPPathDir
) &&
135 file_exists("{$config->customPHPPathDir}/civicrmHooks.php")
137 @include_once
("civicrmHooks.php");
140 if (!empty($fnPrefix)) {
141 $this->commonCiviModules
[$fnPrefix] = $fnPrefix;
144 $this->requireCiviModules($this->commonCiviModules
);
149 * @param $civiModules
161 function runHooks($civiModules, $fnSuffix, $numParams,
162 &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6
164 // $civiModules is *not* passed by reference because runHooks
165 // must be reentrant. PHP is finicky about running
166 // multiple loops over the same variable. The circumstances
167 // to reproduce the issue are pretty intricate.
168 $result = $fResult = array();
170 if ($civiModules !== NULL) {
171 foreach ($civiModules as $module) {
172 $fnName = "{$module}_{$fnSuffix}";
173 if (function_exists($fnName)) {
174 switch ($numParams) {
176 $fResult = $fnName();
180 $fResult = $fnName($arg1);
184 $fResult = $fnName($arg1, $arg2);
188 $fResult = $fnName($arg1, $arg2, $arg3);
192 $fResult = $fnName($arg1, $arg2, $arg3, $arg4);
196 $fResult = $fnName($arg1, $arg2, $arg3, $arg4, $arg5);
200 $fResult = $fnName($arg1, $arg2, $arg3, $arg4, $arg5, $arg6);
204 CRM_Core_Error
::fatal(ts('Invalid hook invocation'));
209 if (!empty($fResult) &&
210 is_array($fResult)) {
211 $result = array_merge($result, $fResult);
216 return empty($result) ?
TRUE : $result;
219 function requireCiviModules(&$moduleList) {
220 $civiModules = CRM_Core_PseudoConstant
::getModuleExtensions();
221 foreach ($civiModules as $civiModule) {
222 if (!file_exists($civiModule['filePath'])) {
223 CRM_Core_Session
::setStatus(
224 ts( 'Error loading module file (%1). Please restore the file or disable the module.',
225 array(1 => $civiModule['filePath']) ),
226 ts( 'Warning'), 'error');
229 include_once $civiModule['filePath'];
230 $moduleList[$civiModule['prefix']] = $civiModule['prefix'];
235 * This hook is called before a db write on some core objects.
236 * This hook does not allow the abort of the operation
238 * @param string $op the type of operation being performed
239 * @param string $objectName the name of the object
240 * @param object $id the object id if available
241 * @param array $params the parameters used for object creation / editing
243 * @return null the return value is ignored
245 static function pre($op, $objectName, $id, &$params) {
246 return self
::singleton()->invoke(4, $op, $objectName, $id, $params, self
::$_nullObject, self
::$_nullObject, 'civicrm_pre');
250 * This hook is called after a db write on some core objects.
252 * @param string $op the type of operation being performed
253 * @param string $objectName the name of the object
254 * @param int $objectId the unique identifier for the object
255 * @param object $objectRef the reference to the object if available
257 * @return mixed based on op. pre-hooks return a boolean or
258 * an error message which aborts the operation
261 static function post($op, $objectName, $objectId, &$objectRef) {
262 return self
::singleton()->invoke(4, $op, $objectName, $objectId, $objectRef, self
::$_nullObject, self
::$_nullObject, 'civicrm_post');
266 * This hook retrieves links from other modules and injects it into
267 * the view contact tabs
269 * @param string $op the type of operation being performed
270 * @param string $objectName the name of the object
271 * @param int $objectId the unique identifier for the object
272 * @param array $links (optional) the links array (introduced in v3.2)
273 * @param int $mask (optional) the bitmask to show/hide links
274 * @param array $values (optional) the values to fill the links
276 * @return null the return value is ignored
278 static function links($op, $objectName, &$objectId, &$links, &$mask = NULL, &$values = array()) {
279 return self
::singleton()->invoke(6, $op, $objectName, $objectId, $links, $mask, $values, 'civicrm_links');
283 * This hook is invoked when building a CiviCRM form. This hook should also
284 * be used to set the default values of a form element
286 * @param string $formName the name of the form
287 * @param object $form reference to the form object
289 * @return null the return value is ignored
291 static function buildForm($formName, &$form) {
292 return self
::singleton()->invoke(2, $formName, $form, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_buildForm');
296 * This hook is invoked when a CiviCRM form is submitted. If the module has injected
297 * any form elements, this hook should save the values in the database
299 * @param string $formName the name of the form
300 * @param object $form reference to the form object
302 * @return null the return value is ignored
304 static function postProcess($formName, &$form) {
305 return self
::singleton()->invoke(2, $formName, $form, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_postProcess');
309 * This hook is invoked during all CiviCRM form validation. An array of errors
310 * detected is returned. Else we assume validation succeeded.
312 * @param string $formName the name of the form
313 * @param array &$fields the POST parameters as filtered by QF
314 * @param array &$files the FILES parameters as sent in by POST
315 * @param array &$form the form object
317 * @return mixed formRule hooks return a boolean or
318 * an array of error messages which display a QF Error
320 static function validate($formName, &$fields, &$files, &$form) {
321 return self
::singleton()->invoke(4, $formName, $fields, $files, $form, self
::$_nullObject, self
::$_nullObject, 'civicrm_validate');
325 * This hook is invoked during all CiviCRM form validation. An array of errors
326 * detected is returned. Else we assume validation succeeded.
328 * @param string $formName the name of the form
329 * @param array &$fields the POST parameters as filtered by QF
330 * @param array &$files the FILES parameters as sent in by POST
331 * @param array &$form the form object
332 * @param array &$errors the array of errors.
334 * @return mixed formRule hooks return a boolean or
335 * an array of error messages which display a QF Error
337 static function validateForm($formName, &$fields, &$files, &$form, &$errors) {
338 return self
::singleton()->invoke(5, $formName, $fields, $files, $form, $errors, self
::$_nullObject, 'civicrm_validateForm');
342 * This hook is called before a db write on a custom table
344 * @param string $op the type of operation being performed
345 * @param string $groupID the custom group ID
346 * @param object $entityID the entityID of the row in the custom table
347 * @param array $params the parameters that were sent into the calling function
349 * @return null the return value is ignored
351 static function custom($op, $groupID, $entityID, &$params) {
352 return self
::singleton()->invoke(4, $op, $groupID, $entityID, $params, self
::$_nullObject, self
::$_nullObject, 'civicrm_custom');
356 * This hook is called when composing the ACL where clause to restrict
357 * visibility of contacts to the logged in user
359 * @param int $type the type of permission needed
360 * @param array $tables (reference ) add the tables that are needed for the select clause
361 * @param array $whereTables (reference ) add the tables that are needed for the where clause
362 * @param int $contactID the contactID for whom the check is made
363 * @param string $where the currrent where clause
365 * @return null the return value is ignored
367 static function aclWhereClause($type, &$tables, &$whereTables, &$contactID, &$where) {
368 return self
::singleton()->invoke(5, $type, $tables, $whereTables, $contactID, $where, self
::$_nullObject, 'civicrm_aclWhereClause');
372 * This hook is called when composing the ACL where clause to restrict
373 * visibility of contacts to the logged in user
375 * @param int $type the type of permission needed
376 * @param int $contactID the contactID for whom the check is made
377 * @param string $tableName the tableName which is being permissioned
378 * @param array $allGroups the set of all the objects for the above table
379 * @param array $currentGroups the set of objects that are currently permissioned for this contact
381 * @return null the return value is ignored
383 static function aclGroup($type, $contactID, $tableName, &$allGroups, &$currentGroups) {
384 return self
::singleton()->invoke(5, $type, $contactID, $tableName, $allGroups, $currentGroups, self
::$_nullObject, 'civicrm_aclGroup');
388 * This hook is called when building the menu table
390 * @param array $files The current set of files to process
392 * @return null the return value is ignored
394 static function xmlMenu(&$files) {
395 return self
::singleton()->invoke(1, $files,
396 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
402 * This hook is called for declaring managed entities via API
404 * @param array $entities List of pending entities
406 * @return null the return value is ignored
409 static function managed(&$entities) {
410 return self
::singleton()->invoke(1, $entities,
411 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
417 * This hook is called when rendering the dashboard (q=civicrm/dashboard)
419 * @param int $contactID - the contactID for whom the dashboard is being rendered
420 * @param int $contentPlacement - (output parameter) where should the hook content be displayed
421 * relative to the activity list
423 * @return string the html snippet to include in the dashboard
426 static function dashboard($contactID, &$contentPlacement = self
::DASHBOARD_BELOW
) {
427 $retval = self
::singleton()->invoke(2, $contactID, $contentPlacement,
428 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
433 * Note we need this seemingly unnecessary code because in the event that the implementation
434 * of the hook declares the second parameter but doesn't set it, then it comes back unset even
435 * though we have a default value in this function's declaration above.
437 if (!isset($contentPlacement)) {
438 $contentPlacement = self
::DASHBOARD_BELOW
;
445 * This hook is called before storing recently viewed items.
447 * @param array $recentArray - an array of recently viewed or processed items, for in place modification
452 static function recent(&$recentArray) {
453 return self
::singleton()->invoke(1, $recentArray,
454 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
460 * This hook is called when building the amount structure for a Contribution or Event Page
462 * @param int $pageType - is this a contribution or event page
463 * @param object $form - reference to the form object
464 * @param array $amount - the amount structure to be displayed
469 static function buildAmount($pageType, &$form, &$amount) {
470 return self
::singleton()->invoke(3, $pageType, $form, $amount, self
::$_nullObject,
471 self
::$_nullObject, self
::$_nullObject, 'civicrm_buildAmount');
475 * This hook is called when building the state list for a particular country.
477 * @param array $countryID
478 * The country id whose states are being selected.
483 static function buildStateProvinceForCountry($countryID, &$states) {
484 return self
::singleton()->invoke(2, $countryID, $states,
485 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
486 'civicrm_buildStateProvinceForCountry'
491 * This hook is called when rendering the tabs for a contact (q=civicrm/contact/view)c
493 * @param array $tabs - the array of tabs that will be displayed
494 * @param int $contactID - the contactID for whom the dashboard is being rendered
498 static function tabs(&$tabs, $contactID) {
499 return self
::singleton()->invoke(2, $tabs, $contactID,
500 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_tabs'
505 * This hook is called when rendering the tabs used for events and potentially
506 * contribution pages, etc.
508 * @param string $tabsetName
509 * Name of the screen or visual element.
511 * Tabs that will be displayed.
512 * @param array $context
513 * Extra data about the screen or context in which the tab is used.
517 static function tabset($tabsetName, &$tabs, $context) {
518 return self
::singleton()->invoke(3, $tabsetName, $tabs,
519 $context, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_tabset'
524 * This hook is called when sending an email / printing labels
526 * @param array $tokens - the list of tokens that can be used for the contact
531 static function tokens(&$tokens) {
532 return self
::singleton()->invoke(1, $tokens,
533 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_tokens'
538 * This hook is called when sending an email / printing labels to get the values for all the
539 * tokens returned by the 'tokens' hook
541 * @param array $details - the array to store the token values indexed by contactIDs (unless it a single)
542 * @param array $contactIDs - an array of contactIDs
543 * @param int $jobID - the jobID if this is associated with a CiviMail mailing
544 * @param array $tokens - the list of tokens associated with the content
545 * @param string $className - the top level className from where the hook is invoked
550 static function tokenValues(&$details,
556 return self
::singleton()->invoke(5, $details, $contactIDs, $jobID, $tokens, $className, self
::$_nullObject, 'civicrm_tokenValues');
560 * This hook is called before a CiviCRM Page is rendered. You can use this hook to insert smarty variables
563 * @param object $page - the page that will be rendered
568 static function pageRun(&$page) {
569 return self
::singleton()->invoke(1, $page,
570 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
576 * This hook is called after a copy of an object has been made. The current objects are
577 * Event, Contribution Page and UFGroup
579 * @param string $objectName - name of the object
580 * @param object $object - reference to the copy
585 static function copy($objectName, &$object) {
586 return self
::singleton()->invoke(2, $objectName, $object,
587 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
593 * This hook is called when a contact unsubscribes from a mailing. It allows modules
594 * to override what the contacts are removed from.
598 * @param int $mailingId
599 * The id of the mailing to unsub from
600 * @param int $contactId
601 * The id of the contact who is unsubscribing
602 * @param array|int $groups
603 * Groups the contact will be removed from.
604 * @param array|int $baseGroups
605 * Base groups (used in smart mailings) the contact will be removed from.
610 static function unsubscribeGroups($op, $mailingId, $contactId, &$groups, &$baseGroups) {
611 return self
::singleton()->invoke(5, $op, $mailingId, $contactId, $groups, $baseGroups, self
::$_nullObject, 'civicrm_unsubscribeGroups');
615 * This hook is called when CiviCRM needs to edit/display a custom field with options (select, radio, checkbox,
618 * @param int $customFieldID - the custom field ID
619 * @param array $options - the current set of options for that custom field.
620 * You can add/remove existing options.
621 * Important: This array may contain meta-data about the field that is needed elsewhere, so it is important
622 * to be careful to not overwrite the array.
623 * Only add/edit/remove the specific field options you intend to affect.
624 * @param boolean $detailedFormat - if true,
625 * the options are in an ID => array ( 'id' => ID, 'label' => label, 'value' => value ) format
629 static function customFieldOptions($customFieldID, &$options, $detailedFormat = FALSE) {
630 return self
::singleton()->invoke(3, $customFieldID, $options, $detailedFormat,
631 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
632 'civicrm_customFieldOptions'
638 * This hook is called to display the list of actions allowed after doing a search.
639 * This allows the module developer to inject additional actions or to remove existing actions.
641 * @param string $objectType - the object type for this search
642 * - activity, campaign, case, contact, contribution, event, grant, membership, and pledge are supported.
643 * @param array $tasks - the current set of tasks for that custom field.
644 * You can add/remove existing tasks.
645 * Each task needs to have a title (eg 'title' => ts( 'Add Contacts to Group')) and a class
646 * (eg 'class' => 'CRM_Contact_Form_Task_AddToGroup').
647 * Optional result (boolean) may also be provided. Class can be an array of classes (not sure what that does :( ).
648 * The key for new Task(s) should not conflict with the keys for core tasks of that $objectType, which can be
649 * found in CRM/$objectType/Task.php.
653 static function searchTasks($objectType, &$tasks) {
654 return self
::singleton()->invoke(2, $objectType, $tasks,
655 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
656 'civicrm_searchTasks'
662 * @param array $params
666 static function eventDiscount(&$form, &$params) {
667 return self
::singleton()->invoke(2, $form, $params,
668 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
669 'civicrm_eventDiscount'
674 * This hook is called when composing a mailing. You can include / exclude other groups as needed.
677 * The form object for which groups / mailings being displayed
678 * @param array $groups
679 * The list of groups being included / excluded
680 * @param array $mailings
681 * The list of mailings being included / excluded
685 static function mailingGroups(&$form, &$groups, &$mailings) {
686 return self
::singleton()->invoke(3, $form, $groups, $mailings,
687 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
688 'civicrm_mailingGroups'
693 * This hook is called when composing the array of membershipTypes and their cost during a membership registration
695 * Note the hook is called on initial page load and also reloaded after submit (PRG pattern).
696 * You can use it to alter the membership types when first loaded, or after submission
697 * (for example if you want to gather data in the form and use it to alter the fees).
700 * The form object that is presenting the page
701 * @param array $membershipTypes
702 * The array of membership types and their amount
706 static function membershipTypeValues(&$form, &$membershipTypes) {
707 return self
::singleton()->invoke(2, $form, $membershipTypes,
708 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
709 'civicrm_membershipTypeValues'
714 * This hook is called when rendering the contact summary
716 * @param int $contactID
717 * The contactID for whom the summary is being rendered
718 * @param mixed $content
719 * @param int $contentPlacement
720 * Specifies where the hook content should be displayed relative to the
724 * The html snippet to include in the contact summary
726 static function summary($contactID, &$content, &$contentPlacement = self
::SUMMARY_BELOW
) {
727 return self
::singleton()->invoke(3, $contactID, $content, $contentPlacement,
728 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
734 * Use this hook to populate the list of contacts returned by Contact Reference custom fields.
735 * By default, Contact Reference fields will search on and return all CiviCRM contacts.
736 * If you want to limit the contacts returned to a specific group, or some other criteria
737 * - you can override that behavior by providing a SQL query that returns some subset of your contacts.
738 * The hook is called when the query is executed to get the list of contacts to display.
740 * @param mixed $query - - the query that will be executed (input and output parameter);
741 * It's important to realize that the ACL clause is built prior to this hook being fired,
742 * so your query will ignore any ACL rules that may be defined.
743 * Your query must return two columns:
744 * the contact 'data' to display in the autocomplete dropdown (usually contact.sort_name - aliased as 'data')
746 * @param string $name - the name string to execute the query against (this is the value being typed in by the user)
747 * @param string $context - the context in which this ajax call is being made (for example: 'customfield', 'caseview')
748 * @param int $id - the id of the object for which the call is being made.
749 * For custom fields, it will be the custom field id
753 static function contactListQuery(&$query, $name, $context, $id) {
754 return self
::singleton()->invoke(4, $query, $name, $context, $id,
755 self
::$_nullObject, self
::$_nullObject,
756 'civicrm_contactListQuery'
761 * Hook definition for altering payment parameters before talking to a payment processor back end.
763 * Definition will look like this:
765 * function hook_civicrm_alterPaymentProcessorParams($paymentObj,
766 * &$rawParams, &$cookedParams);
768 * @param string $paymentObj
769 * instance of payment class of the payment processor invoked (e.g., 'CRM_Core_Payment_Dummy')
770 * @param array &$rawParams
771 * array of params as passed to to the processor
772 * @param array &$cookedParams
773 * params after the processor code has translated them into its own key/value pairs
777 static function alterPaymentProcessorParams($paymentObj,
781 return self
::singleton()->invoke(3, $paymentObj, $rawParams, $cookedParams,
782 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
783 'civicrm_alterPaymentProcessorParams'
788 * This hook is called when an email is about to be sent by CiviCRM.
790 * @param array $params
791 * Array fields include: groupName, from, toName, toEmail, subject, cc, bcc, text, html,
792 * returnPath, replyTo, headers, attachments (array)
793 * @param string $context - the context in which the hook is being invoked, eg 'civimail'
797 static function alterMailParams(&$params, $context = NULL) {
798 return self
::singleton()->invoke(2, $params, $context,
799 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
800 'civicrm_alterMailParams'
805 * This hook is called when membership status is being calculated
807 * @param array $membershipStatus membership status details as determined - alter if required
808 * @param array $arguments arguments passed in to calculate date
813 * - 'exclude_is_admin'
814 * - 'membership_type_id'
815 * @param array $membership membership details from the calling function
817 static function alterCalculatedMembershipStatus(&$membershipStatus, $arguments, $membership) {
818 return self
::singleton()->invoke(3, $membershipStatus, $arguments,
819 $membership, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
820 'civicrm_alterCalculatedMembershipStatus'
825 * This hook is called when rendering the Manage Case screen
827 * @param int $caseID - the case ID
829 * @return array of data to be displayed, where the key is a unique id to be used for styling (div id's)
830 * and the value is an array with keys 'label' and 'value' specifying label/value pairs
833 static function caseSummary($caseID) {
834 return self
::singleton()->invoke(1, $caseID,
835 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
836 'civicrm_caseSummary'
841 * This hook is called when locating CiviCase types.
843 * @param array $caseTypes
847 static function caseTypes(&$caseTypes) {
848 return self
::singleton()->invoke(1, $caseTypes, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_caseTypes');
852 * This hook is called soon after the CRM_Core_Config object has ben initialized.
853 * You can use this hook to modify the config object and hence behavior of CiviCRM dynamically.
855 * @param CRM_Core_Config|array $config
860 static function config(&$config) {
861 return self
::singleton()->invoke(1, $config,
862 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
867 static function enableDisable($recordBAO, $recordID, $isActive) {
868 return self
::singleton()->invoke(3, $recordBAO, $recordID, $isActive,
869 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
870 'civicrm_enableDisable'
875 * This hooks allows to change option values
877 * @param array $options
878 * Associated array of option values / id
879 * @param string $name
884 static function optionValues(&$options, $name) {
885 return self
::singleton()->invoke(2, $options, $name,
886 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
887 'civicrm_optionValues'
892 * This hook allows modification of the navigation menu.
894 * @param array $params
895 * Associated array of navigation menu entry to Modify/Add
899 static function navigationMenu(&$params) {
900 return self
::singleton()->invoke(1, $params,
901 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
902 'civicrm_navigationMenu'
907 * This hook allows modification of the data used to perform merging of duplicates.
909 * @param string $type the type of data being passed (cidRefs|eidRefs|relTables|sqls)
910 * @param array $data the data, as described in $type
911 * @param int $mainId contact_id of the contact that survives the merge
912 * @param int $otherId contact_id of the contact that will be absorbed and deleted
913 * @param array $tables when $type is "sqls", an array of tables as it may have been handed to the calling function
917 static function merge($type, &$data, $mainId = NULL, $otherId = NULL, $tables = NULL) {
918 return self
::singleton()->invoke(5, $type, $data, $mainId, $otherId, $tables, self
::$_nullObject, 'civicrm_merge');
922 * This hook provides a way to override the default privacy behavior for notes.
924 * @param array &$noteValues
925 * Associative array of values for this note
929 static function notePrivacy(&$noteValues) {
930 return self
::singleton()->invoke(1, $noteValues,
931 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
932 'civicrm_notePrivacy'
937 * This hook is called before record is exported as CSV
939 * @param string $exportTempTable - name of the temporary export table used during export
940 * @param array $headerRows - header rows for output
941 * @param array $sqlColumns - SQL columns
942 * @param int $exportMode - export mode ( contact, contribution, etc...)
946 static function export(&$exportTempTable, &$headerRows, &$sqlColumns, &$exportMode) {
947 return self
::singleton()->invoke(4, $exportTempTable, $headerRows, $sqlColumns, $exportMode,
948 self
::$_nullObject, self
::$_nullObject,
954 * This hook allows modification of the queries constructed from dupe rules.
956 * @param string $obj object of rulegroup class
957 * @param string $type type of queries e.g table / threshold
958 * @param array $query set of queries
962 static function dupeQuery($obj, $type, &$query) {
963 return self
::singleton()->invoke(3, $obj, $type, $query,
964 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
970 * This hook is called AFTER EACH email has been processed by the script bin/EmailProcessor.php
972 * @param string $type type of mail processed: 'activity' OR 'mailing'
973 * @param array &$params the params that were sent to the CiviCRM API function
974 * @param object $mail the mail object which is an ezcMail class
975 * @param array &$result the result returned by the api call
976 * @param string $action (optional ) the requested action to be performed if the types was 'mailing'
980 static function emailProcessor($type, &$params, $mail, &$result, $action = NULL) {
981 return self
::singleton()->invoke(5, $type, $params, $mail, $result, $action, self
::$_nullObject, 'civicrm_emailProcessor');
985 * This hook is called after a row has been processed and the
986 * record (and associated records imported
988 * @param string $object - object being imported (for now Contact only, later Contribution, Activity,
989 * Participant and Member)
990 * @param string $usage - hook usage/location (for now process only, later mapping and others)
991 * @param string $objectRef - import record object
992 * @param array $params - array with various key values: currently
993 * contactID - contact id
994 * importID - row id in temp table
995 * importTempTable - name of tempTable
996 * fieldHeaders - field headers
997 * fields - import fields
1002 static function import($object, $usage, &$objectRef, &$params) {
1003 return self
::singleton()->invoke(4, $object, $usage, $objectRef, $params,
1004 self
::$_nullObject, self
::$_nullObject,
1010 * This hook is called when API permissions are checked (cf. civicrm_api3_api_check_permission()
1011 * in api/v3/utils.php and _civicrm_api3_permissions() in CRM/Core/DAO/permissions.php).
1013 * @param string $entity the API entity (like contact)
1014 * @param string $action the API action (like get)
1015 * @param array &$params the API parameters
1016 * @param array &$permisisons the associative permissions array (probably to be altered by this hook)
1018 static function alterAPIPermissions($entity, $action, &$params, &$permissions) {
1019 return self
::singleton()->invoke(4, $entity, $action, $params, $permissions,
1020 self
::$_nullObject, self
::$_nullObject,
1021 'civicrm_alterAPIPermissions'
1025 static function postSave(&$dao) {
1026 $hookName = 'civicrm_postSave_' . $dao->getTableName();
1027 return self
::singleton()->invoke(1, $dao,
1028 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1034 * This hook allows user to customize context menu Actions on contact summary page.
1036 * @param array $actions Array of all Actions in contextmenu.
1037 * @param int $contactID ContactID for the summary page
1039 static function summaryActions(&$actions, $contactID = NULL) {
1040 return self
::singleton()->invoke(2, $actions, $contactID,
1041 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1042 'civicrm_summaryActions'
1047 * This hook is called from CRM_Core_Selector_Controller through which all searches in civicrm go.
1048 * This enables us hook implementors to modify both the headers and the rows
1050 * The BIGGEST drawback with this hook is that you may need to modify the result template to include your
1051 * fields. The result files are CRM/{Contact,Contribute,Member,Event...}/Form/Selector.tpl
1053 * However, if you use the same number of columns, you can overwrite the existing columns with the values that
1054 * you want displayed. This is a hackish, but avoids template modification.
1056 * @param string $objectName the component name that we are doing the search
1057 * activity, campaign, case, contact, contribution, event, grant, membership, and pledge
1058 * @param array &$headers the list of column headers, an associative array with keys: ( name, sort, order )
1059 * @param array &$rows the list of values, an associate array with fields that are displayed for that component
1060 * @param array &$seletor the selector object. Allows you access to the context of the search
1062 * @return void modify the header and values object to pass the data u need
1064 static function searchColumns($objectName, &$headers, &$rows, &$selector) {
1065 return self
::singleton()->invoke(4, $objectName, $headers, $rows, $selector,
1066 self
::$_nullObject, self
::$_nullObject,
1067 'civicrm_searchColumns'
1072 * This hook is called when uf groups are being built for a module.
1074 * @param string $moduleName module name.
1075 * @param array $ufGroups array of ufgroups for a module.
1080 static function buildUFGroupsForModule($moduleName, &$ufGroups) {
1081 return self
::singleton()->invoke(2, $moduleName, $ufGroups,
1082 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1083 'civicrm_buildUFGroupsForModule'
1088 * This hook is called when we are determining the contactID for a specific
1091 * @param string $email the email address
1092 * @param int $contactID the contactID that matches this email address, IF it exists
1093 * @param array $result (reference) has two fields
1094 * contactID - the new (or same) contactID
1095 * action - 3 possible values:
1096 * CRM_Utils_Mail_Incoming::EMAILPROCESSOR_CREATE_INDIVIDUAL - create a new contact record
1097 * CRM_Utils_Mail_Incoming::EMAILPROCESSOR_OVERRIDE - use the new contactID
1098 * CRM_Utils_Mail_Incoming::EMAILPROCESSOR_IGNORE - skip this email address
1103 static function emailProcessorContact($email, $contactID, &$result) {
1104 return self
::singleton()->invoke(3, $email, $contactID, $result,
1105 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1106 'civicrm_emailProcessorContact'
1111 * Hook definition for altering the generation of Mailing Labels
1113 * @param array $args an array of the args in the order defined for the tcpdf multiCell api call
1114 * with the variable names below converted into string keys (ie $w become 'w'
1115 * as the first key for $args)
1116 * float $w Width of cells. If 0, they extend up to the right margin of the page.
1117 * float $h Cell minimum height. The cell extends automatically if needed.
1118 * string $txt String to print
1119 * mixed $border Indicates if borders must be drawn around the cell block. The value can
1120 * be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or
1121 * a string containing some or all of the following characters (in any order):
1122 * <ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul>
1123 * string $align Allows to center or align the text. Possible values are:<ul><li>L or empty string:
1124 * left align</li><li>C: center</li><li>R: right align</li><li>J: justification
1125 * (default value when $ishtml=false)</li></ul>
1126 * int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
1127 * int $ln Indicates where the current position should go after the call. Possible values are:<ul><li>0:
1128 * to the right</li><li>1: to the beginning of the next line [DEFAULT]</li><li>2: below</li></ul>
1129 * float $x x position in user units
1130 * float $y y position in user units
1131 * boolean $reseth if true reset the last cell height (default true).
1132 * int $stretch stretch carachter mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if
1133 * necessary</li><li>2 = forced horizontal scaling</li><li>3 = character spacing only if
1134 * necessary</li><li>4 = forced character spacing</li></ul>
1135 * boolean $ishtml set to true if $txt is HTML content (default = false).
1136 * boolean $autopadding if true, uses internal padding and automatically adjust it to account for line width.
1137 * float $maxh maximum height. It should be >= $h and less then remaining space to the bottom of the page,
1138 * or 0 for disable this feature. This feature works only when $ishtml=false.
1141 static function alterMailingLabelParams(&$args) {
1142 return self
::singleton()->invoke(1, $args,
1143 self
::$_nullObject, self
::$_nullObject,
1144 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1145 'civicrm_alterMailingLabelParams'
1150 * This hooks allows alteration of generated page content
1152 * @param $content previously generated content
1153 * @param $context context of content - page or form
1154 * @param $tplName the file name of the tpl
1155 * @param $object a reference to the page or form object
1159 static function alterContent(&$content, $context, $tplName, &$object) {
1160 return self
::singleton()->invoke(4, $content, $context, $tplName, $object,
1161 self
::$_nullObject, self
::$_nullObject,
1162 'civicrm_alterContent'
1167 * This hooks allows alteration of the tpl file used to generate content. It differs from the
1168 * altercontent hook as the content has already been rendered through the tpl at that point
1170 * @param $formName previously generated content
1171 * @param $form reference to the form object
1172 * @param $context context of content - page or form
1173 * @param $tplName reference the file name of the tpl
1177 static function alterTemplateFile($formName, &$form, $context, &$tplName) {
1178 return self
::singleton()->invoke(4, $formName, $form, $context, $tplName,
1179 self
::$_nullObject, self
::$_nullObject,
1180 'civicrm_alterTemplateFile'
1184 * This hook collects the trigger definition from all components
1186 * @param $triggerInfo reference to an array of trigger information
1187 * each element has 4 fields:
1188 * table - array of tableName
1189 * when - BEFORE or AFTER
1190 * event - array of eventName - INSERT OR UPDATE OR DELETE
1191 * sql - array of statements optionally terminated with a ;
1192 * a statement can use the tokes {tableName} and {eventName}
1193 * to do token replacement with the table / event. This allows
1194 * templatizing logging and other hooks
1195 * @param string $tableName (optional) the name of the table that we are interested in only
1197 static function triggerInfo(&$info, $tableName = NULL) {
1198 return self
::singleton()->invoke(2, $info, $tableName,
1199 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1201 'civicrm_triggerInfo'
1206 * This hook is called when a module-extension is installed.
1207 * Each module will receive hook_civicrm_install during its own installation (but not during the
1208 * installation of unrelated modules).
1210 static function install() {
1211 return self
::singleton()->invoke(0, self
::$_nullObject,
1212 self
::$_nullObject, self
::$_nullObject,
1213 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1219 * This hook is called when a module-extension is uninstalled.
1220 * Each module will receive hook_civicrm_uninstall during its own uninstallation (but not during the
1221 * uninstallation of unrelated modules).
1223 static function uninstall() {
1224 return self
::singleton()->invoke(0, self
::$_nullObject,
1225 self
::$_nullObject, self
::$_nullObject,
1226 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1232 * This hook is called when a module-extension is re-enabled.
1233 * Each module will receive hook_civicrm_enable during its own re-enablement (but not during the
1234 * re-enablement of unrelated modules).
1236 static function enable() {
1237 return self
::singleton()->invoke(0, self
::$_nullObject,
1238 self
::$_nullObject, self
::$_nullObject,
1239 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1245 * This hook is called when a module-extension is disabled.
1246 * Each module will receive hook_civicrm_disable during its own disablement (but not during the
1247 * disablement of unrelated modules).
1249 static function disable() {
1250 return self
::singleton()->invoke(0, self
::$_nullObject,
1251 self
::$_nullObject, self
::$_nullObject,
1252 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1257 static function alterReportVar($varType, &$var, &$object) {
1258 return self
::singleton()->invoke(3, $varType, $var, $object,
1260 self
::$_nullObject, self
::$_nullObject,
1261 'civicrm_alterReportVar'
1266 * This hook is called to drive database upgrades for extension-modules.
1269 * The type of operation being performed; 'check' or 'enqueue'.
1270 * @param CRM_Queue_Queue $queue
1271 * (for 'enqueue') the modifiable list of pending up upgrade tasks.
1274 * NULL, if $op is 'enqueue'.
1275 * TRUE, if $op is 'check' and upgrades are pending.
1276 * FALSE, if $op is 'check' and upgrades are not pending.
1278 static function upgrade($op, CRM_Queue_Queue
$queue = NULL) {
1279 return self
::singleton()->invoke(2, $op, $queue,
1280 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1287 * This hook is called when an email has been successfully sent by CiviCRM, but not on an error.
1289 * @param array $params
1290 * The mailing parameters. Array fields include: groupName, from, toName,
1291 * toEmail, subject, cc, bcc, text, html, returnPath, replyTo, headers,
1292 * attachments (array)
1296 static function postEmailSend(&$params) {
1297 return self
::singleton()->invoke(1, $params,
1298 self
::$_nullObject, self
::$_nullObject,
1299 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1300 'civicrm_postEmailSend'
1305 * This hook is called when Settings specifications are loaded
1307 * @param array $settingsFolders
1308 * List of paths from which to derive metadata
1312 static function alterSettingsFolders(&$settingsFolders) {
1313 return self
::singleton()->invoke(1, $settingsFolders,
1314 self
::$_nullObject, self
::$_nullObject,
1315 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1316 'civicrm_alterSettingsFolders'
1321 * This hook is called when Settings have been loaded from the xml
1322 * It is an opportunity for hooks to alter the data
1324 * @param array $settingsMetaData - Settings Metadata
1325 * @param int $domainID
1326 * @param mixed $profile
1330 static function alterSettingsMetaData(&$settingsMetaData, $domainID, $profile) {
1331 return self
::singleton()->invoke(3, $settingsMetaData,
1332 $domainID, $profile,
1333 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1334 'civicrm_alterSettingsMetaData'
1339 * This hook is called before running an api call.
1341 * @param API_Wrapper[] $wrappers
1342 * (see CRM_Utils_API_ReloadOption as an example)
1343 * @param mixed $apiRequest
1346 * The return value is ignored
1348 static function apiWrappers(&$wrappers, $apiRequest) {
1349 return self
::singleton()
1350 ->invoke(2, $wrappers, $apiRequest, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1351 self
::$_nullObject, 'civicrm_apiWrappers'
1356 * This hook is called before running pending cron jobs.
1358 * @param CRM_Core_JobManager $jobManager
1361 * The return value is ignored.
1363 static function cron($jobManager) {
1364 return self
::singleton()->invoke(1,
1365 $jobManager, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1371 * This hook is called when loading CMS permissions; use this hook to modify
1372 * the array of system permissions for CiviCRM.
1374 * @param array $permissions
1375 * Array of permissions. See CRM_Core_Permission::getCorePermissions() for
1376 * the format of this array.
1379 * The return value is ignored
1381 static function permission(&$permissions) {
1382 return self
::singleton()->invoke(1, $permissions,
1383 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1384 'civicrm_permission'
1390 * This hook is called for declaring managed entities via API
1392 * @param array[] $entityTypes
1393 * List of entity types; each entity-type is an array with keys:
1394 * - name: string, a unique short name (e.g. "ReportInstance")
1395 * - class: string, a PHP DAO class (e.g. "CRM_Report_DAO_Instance")
1396 * - table: string, a SQL table name (e.g. "civicrm_report_instance")
1399 * The return value is ignored
1401 static function entityTypes(&$entityTypes) {
1402 return self
::singleton()->invoke(1, $entityTypes, self
::$_nullObject, self
::$_nullObject,
1403 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_entityTypes'
1408 * This hook is called while preparing a profile form
1410 * @param string $name
1413 static function buildProfile($name) {
1414 return self
::singleton()->invoke(1, $name, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1415 self
::$_nullObject, self
::$_nullObject, 'civicrm_buildProfile');
1419 * This hook is called while validating a profile form submission
1421 * @param string $name
1424 static function validateProfile($name) {
1425 return self
::singleton()->invoke(1, $name, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1426 self
::$_nullObject, self
::$_nullObject, 'civicrm_validateProfile');
1430 * This hook is called processing a valid profile form submission
1432 * @param string $name
1435 static function processProfile($name) {
1436 return self
::singleton()->invoke(1, $name, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1437 self
::$_nullObject, self
::$_nullObject, 'civicrm_processProfile');
1441 * This hook is called while preparing a read-only profile screen
1443 * @param string $name
1446 static function viewProfile($name) {
1447 return self
::singleton()->invoke(1, $name, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1448 self
::$_nullObject, self
::$_nullObject, 'civicrm_viewProfile');
1452 * This hook is called while preparing a list of contacts (based on a profile)
1454 * @param string $name
1457 static function searchProfile($name) {
1458 return self
::singleton()->invoke(1, $name, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1459 self
::$_nullObject, self
::$_nullObject, 'civicrm_searchProfile');
1463 * This hook is called before encoding data in barcode
1465 * @param array $data associated array of values available for encoding
1466 * @param string $type type of barcode, classic barcode or QRcode
1467 * @param string $context where this hooks is invoked.
1471 static function alterBarcode( &$data, $type = 'barcode', $context = 'name_badge' ) {
1472 return self
::singleton()->invoke(3, $data, $type, $context, self
::$_nullObject,
1473 self
::$_nullObject, self
::$_nullObject, 'civicrm_alterBarcode');
1477 * Modify or replace the Mailer object used for outgoing mail.
1479 * @param object $mailer
1480 * The default mailer produced by normal configuration; a PEAR "Mail" class (like those returned by Mail::factory)
1481 * @param string $driver
1482 * The type of the default mailer (eg "smtp", "sendmail", "mock", "CRM_Mailing_BAO_Spool")
1483 * @param array $params
1484 * The default mailer config options
1487 * @see Mail::factory
1489 static function alterMail(&$mailer, $driver, $params) {
1490 return self
::singleton()
1491 ->invoke(3, $mailer, $driver, $params, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_alterMailer');
1495 * This hook is called while building the core search query,
1496 * so hook implementers can provide their own query objects which alters/extends core search.
1498 * @param array $queryObjects
1499 * @param string $type
1503 static function queryObjects(&$queryObjects, $type = 'Contact') {
1504 return self
::singleton()->invoke(2, $queryObjects, $type, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_queryObjects');
1508 * This hook is called while viewing contact dashboard
1510 * @param array $availableDashlets
1511 * List of dashlets; each is formatted per api/v3/Dashboard
1512 * @param array $defaultDashlets
1513 * List of dashlets; each is formatted per api/v3/DashboardContact
1517 static function dashboard_defaults($availableDashlets, &$defaultDashlets) {
1518 return self
::singleton()->invoke(2, $availableDashlets, $defaultDashlets, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_dashboard_defaults');