3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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-2017
33 abstract class CRM_Utils_Hook
{
35 // Allowed values for dashboard hook content placement
36 // Default - place content below activity list
37 const DASHBOARD_BELOW
= 1;
38 // Place content above activity list
39 const DASHBOARD_ABOVE
= 2;
40 // Don't display activity list at all
41 const DASHBOARD_REPLACE
= 3;
43 // by default - place content below existing content
44 const SUMMARY_BELOW
= 1;
45 // place hook content above
46 const SUMMARY_ABOVE
= 2;
47 // create your own summaries
48 const SUMMARY_REPLACE
= 3;
50 static $_nullObject = NULL;
53 * We only need one instance of this object. So we use the singleton
54 * pattern and cache the instance in this variable
58 static private $_singleton = NULL;
63 private $commonIncluded = FALSE;
68 private $commonCiviModules = array();
71 * @var CRM_Utils_Cache_Interface
76 * Constructor and getter for the singleton instance.
81 * An instance of $config->userHookClass
83 public static function singleton($fresh = FALSE) {
84 if (self
::$_singleton == NULL ||
$fresh) {
85 $config = CRM_Core_Config
::singleton();
86 $class = $config->userHookClass
;
87 self
::$_singleton = new $class();
89 return self
::$_singleton;
93 * CRM_Utils_Hook constructor.
95 public function __construct() {
96 $this->cache
= CRM_Utils_Cache
::create(array(
98 'type' => array('ArrayCache'),
106 * @param int $numParams
107 * Number of parameters to pass to the hook.
109 * Parameter to be passed to the hook.
111 * Parameter to be passed to the hook.
113 * Parameter to be passed to the hook.
115 * Parameter to be passed to the hook.
117 * Parameter to be passed to the hook.
119 * Parameter to be passed to the hook.
120 * @param string $fnSuffix
121 * Function suffix, this is effectively the hook name.
125 public abstract function invoke(
127 &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6,
132 * @param array $numParams
144 public function commonInvoke(
146 &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6,
150 $this->commonBuildModuleList($fnPrefix);
152 return $this->runHooks($this->commonCiviModules
, $fnSuffix,
153 $numParams, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6
158 * Build the list of modules to be processed for hooks.
160 * @param string $fnPrefix
162 public function commonBuildModuleList($fnPrefix) {
163 if (!$this->commonIncluded
) {
164 // include external file
165 $this->commonIncluded
= TRUE;
167 $config = CRM_Core_Config
::singleton();
168 if (!empty($config->customPHPPathDir
) &&
169 file_exists("{$config->customPHPPathDir}/civicrmHooks.php")
171 @include_once
"civicrmHooks.php";
174 if (!empty($fnPrefix)) {
175 $this->commonCiviModules
[$fnPrefix] = $fnPrefix;
178 $this->requireCiviModules($this->commonCiviModules
);
183 * @param $civiModules
185 * @param array $numParams
195 public function runHooks(
196 $civiModules, $fnSuffix, $numParams,
197 &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6
199 // $civiModules is *not* passed by reference because runHooks
200 // must be reentrant. PHP is finicky about running
201 // multiple loops over the same variable. The circumstances
202 // to reproduce the issue are pretty intricate.
205 $fnNames = $this->cache
->get($fnSuffix);
206 if (!is_array($fnNames)) {
208 if ($civiModules !== NULL) {
209 foreach ($civiModules as $module) {
210 $fnName = "{$module}_{$fnSuffix}";
211 if (function_exists($fnName)) {
212 $fnNames[] = $fnName;
215 $this->cache
->set($fnSuffix, $fnNames);
219 foreach ($fnNames as $fnName) {
221 switch ($numParams) {
223 $fResult = $fnName();
227 $fResult = $fnName($arg1);
231 $fResult = $fnName($arg1, $arg2);
235 $fResult = $fnName($arg1, $arg2, $arg3);
239 $fResult = $fnName($arg1, $arg2, $arg3, $arg4);
243 $fResult = $fnName($arg1, $arg2, $arg3, $arg4, $arg5);
247 $fResult = $fnName($arg1, $arg2, $arg3, $arg4, $arg5, $arg6);
251 CRM_Core_Error
::fatal(ts('Invalid hook invocation'));
255 if (!empty($fResult) &&
258 $result = array_merge($result, $fResult);
262 return empty($result) ?
TRUE : $result;
268 public function requireCiviModules(&$moduleList) {
269 $civiModules = CRM_Core_PseudoConstant
::getModuleExtensions();
270 foreach ($civiModules as $civiModule) {
271 if (!file_exists($civiModule['filePath'])) {
272 CRM_Core_Session
::setStatus(
273 ts('Error loading module file (%1). Please restore the file or disable the module.',
274 array(1 => $civiModule['filePath'])),
275 ts('Warning'), 'error');
278 include_once $civiModule['filePath'];
279 $moduleList[$civiModule['prefix']] = $civiModule['prefix'];
284 * This hook is called before a db write on some core objects.
285 * This hook does not allow the abort of the operation
288 * The type of operation being performed.
289 * @param string $objectName
290 * The name of the object.
292 * The object id if available.
293 * @param array $params
294 * The parameters used for object creation / editing.
297 * the return value is ignored
299 public static function pre($op, $objectName, $id, &$params) {
300 $event = new \Civi\Core\Event\
PreEvent($op, $objectName, $id, $params);
301 \Civi
::service('dispatcher')->dispatch("hook_civicrm_pre", $event);
302 \Civi
::service('dispatcher')->dispatch("hook_civicrm_pre::$objectName", $event);
303 return self
::singleton()
304 ->invoke(4, $op, $objectName, $id, $params, self
::$_nullObject, self
::$_nullObject, 'civicrm_pre');
308 * This hook is called after a db write on some core objects.
311 * The type of operation being performed.
312 * @param string $objectName
313 * The name of the object.
314 * @param int $objectId
315 * The unique identifier for the object.
316 * @param object $objectRef
317 * The reference to the object if available.
320 * based on op. pre-hooks return a boolean or
321 * an error message which aborts the operation
323 public static function post($op, $objectName, $objectId, &$objectRef = NULL) {
324 $event = new \Civi\Core\Event\
PostEvent($op, $objectName, $objectId, $objectRef);
325 \Civi
::service('dispatcher')->dispatch("hook_civicrm_post", $event);
326 \Civi
::service('dispatcher')->dispatch("hook_civicrm_post::$objectName", $event);
327 return self
::singleton()
328 ->invoke(4, $op, $objectName, $objectId, $objectRef, self
::$_nullObject, self
::$_nullObject, 'civicrm_post');
332 * This hook retrieves links from other modules and injects it into.
333 * the view contact tabs
336 * The type of operation being performed.
337 * @param string $objectName
338 * The name of the object.
339 * @param int $objectId
340 * The unique identifier for the object.
341 * @param array $links
342 * (optional) the links array (introduced in v3.2).
344 * (optional) the bitmask to show/hide links.
345 * @param array $values
346 * (optional) the values to fill the links.
349 * the return value is ignored
351 public static function links($op, $objectName, &$objectId, &$links, &$mask = NULL, &$values = array()) {
352 return self
::singleton()->invoke(6, $op, $objectName, $objectId, $links, $mask, $values, 'civicrm_links');
356 * This hook is invoked during the CiviCRM form preProcess phase.
358 * @param string $formName
359 * The name of the form.
360 * @param CRM_Core_Form $form
361 * Reference to the form object.
364 * the return value is ignored
366 public static function preProcess($formName, &$form) {
367 return self
::singleton()
368 ->invoke(2, $formName, $form, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_preProcess');
372 * This hook is invoked when building a CiviCRM form. This hook should also
373 * be used to set the default values of a form element
375 * @param string $formName
376 * The name of the form.
377 * @param CRM_Core_Form $form
378 * Reference to the form object.
381 * the return value is ignored
383 public static function buildForm($formName, &$form) {
384 return self
::singleton()->invoke(2, $formName, $form,
385 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
391 * This hook is invoked when a CiviCRM form is submitted. If the module has injected
392 * any form elements, this hook should save the values in the database
394 * @param string $formName
395 * The name of the form.
396 * @param CRM_Core_Form $form
397 * Reference to the form object.
400 * the return value is ignored
402 public static function postProcess($formName, &$form) {
403 return self
::singleton()->invoke(2, $formName, $form,
404 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
405 'civicrm_postProcess'
410 * This hook is invoked during all CiviCRM form validation. An array of errors
411 * detected is returned. Else we assume validation succeeded.
413 * @param string $formName
414 * The name of the form.
415 * @param array &$fields the POST parameters as filtered by QF
416 * @param array &$files the FILES parameters as sent in by POST
417 * @param array &$form the form object
418 * @param array &$errors the array of errors.
421 * formRule hooks return a boolean or
422 * an array of error messages which display a QF Error
424 public static function validateForm($formName, &$fields, &$files, &$form, &$errors) {
425 return self
::singleton()
426 ->invoke(5, $formName, $fields, $files, $form, $errors, self
::$_nullObject, 'civicrm_validateForm');
430 * This hook is called after a db write on a custom table.
433 * The type of operation being performed.
434 * @param string $groupID
435 * The custom group ID.
436 * @param object $entityID
437 * The entityID of the row in the custom table.
438 * @param array $params
439 * The parameters that were sent into the calling function.
442 * the return value is ignored
444 public static function custom($op, $groupID, $entityID, &$params) {
445 return self
::singleton()
446 ->invoke(4, $op, $groupID, $entityID, $params, self
::$_nullObject, self
::$_nullObject, 'civicrm_custom');
450 * This hook is called when composing the ACL where clause to restrict
451 * visibility of contacts to the logged in user
454 * The type of permission needed.
455 * @param array $tables
456 * (reference ) add the tables that are needed for the select clause.
457 * @param array $whereTables
458 * (reference ) add the tables that are needed for the where clause.
459 * @param int $contactID
460 * The contactID for whom the check is made.
461 * @param string $where
462 * The currrent where clause.
465 * the return value is ignored
467 public static function aclWhereClause($type, &$tables, &$whereTables, &$contactID, &$where) {
468 return self
::singleton()
469 ->invoke(5, $type, $tables, $whereTables, $contactID, $where, self
::$_nullObject, 'civicrm_aclWhereClause');
473 * This hook is called when composing the ACL where clause to restrict
474 * visibility of contacts to the logged in user
477 * The type of permission needed.
478 * @param int $contactID
479 * The contactID for whom the check is made.
480 * @param string $tableName
481 * The tableName which is being permissioned.
482 * @param array $allGroups
483 * The set of all the objects for the above table.
484 * @param array $currentGroups
485 * The set of objects that are currently permissioned for this contact.
488 * the return value is ignored
490 public static function aclGroup($type, $contactID, $tableName, &$allGroups, &$currentGroups) {
491 return self
::singleton()
492 ->invoke(5, $type, $contactID, $tableName, $allGroups, $currentGroups, self
::$_nullObject, 'civicrm_aclGroup');
496 * @param string|CRM_Core_DAO $entity
497 * @param array $clauses
500 public static function selectWhereClause($entity, &$clauses) {
501 $entityName = is_object($entity) ?
_civicrm_api_get_entity_name_from_dao($entity) : $entity;
502 return self
::singleton()->invoke(2, $entityName, $clauses,
503 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
504 'civicrm_selectWhereClause'
509 * This hook is called when building the menu table.
511 * @param array $files
512 * The current set of files to process.
515 * the return value is ignored
517 public static function xmlMenu(&$files) {
518 return self
::singleton()->invoke(1, $files,
519 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
525 * (Experimental) This hook is called when build the menu table.
527 * @param array $items
528 * List of records to include in menu table.
530 * the return value is ignored
532 public static function alterMenu(&$items) {
533 return self
::singleton()->invoke(1, $items,
534 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
540 * This hook is called for declaring managed entities via API.
542 * @param array $entities
543 * List of pending entities. Each entity is an array with keys:
544 * + 'module': string; for module-extensions, this is the fully-qualifed name (e.g. "com.example.mymodule"); for CMS modules, the name is prefixed by the CMS (e.g. "drupal.mymodule")
545 * + 'name': string, a symbolic name which can be used to track this entity (Note: Each module creates its own namespace)
546 * + 'entity': string, an entity-type supported by the CiviCRM API (Note: this currently must be an entity which supports the 'is_active' property)
547 * + 'params': array, the entity data as supported by the CiviCRM API
548 * + 'update' (v4.5+): string, a policy which describes when to update records
549 * - 'always' (default): always update the managed-entity record; changes in $entities will override any local changes (eg by the site-admin)
550 * - 'never': never update the managed-entity record; changes made locally (eg by the site-admin) will override changes in $entities
551 * + 'cleanup' (v4.5+): string, a policy which describes whether to cleanup the record when it becomes orphaned (ie when $entities no longer references the record)
552 * - 'always' (default): always delete orphaned records
553 * - 'never': never delete orphaned records
554 * - 'unused': only delete orphaned records if there are no other references to it in the DB. (This is determined by calling the API's "getrefcount" action.)
557 * the return value is ignored
559 public static function managed(&$entities) {
560 return self
::singleton()->invoke(1, $entities,
561 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
567 * This hook is called when rendering the dashboard (q=civicrm/dashboard)
569 * @param int $contactID
570 * The contactID for whom the dashboard is being rendered.
571 * @param int $contentPlacement
572 * (output parameter) where should the hook content be displayed.
573 * relative to the activity list
576 * the html snippet to include in the dashboard
578 public static function dashboard($contactID, &$contentPlacement = self
::DASHBOARD_BELOW
) {
579 $retval = self
::singleton()->invoke(2, $contactID, $contentPlacement,
580 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
585 * Note we need this seemingly unnecessary code because in the event that the implementation
586 * of the hook declares the second parameter but doesn't set it, then it comes back unset even
587 * though we have a default value in this function's declaration above.
589 if (!isset($contentPlacement)) {
590 $contentPlacement = self
::DASHBOARD_BELOW
;
597 * This hook is called before storing recently viewed items.
599 * @param array $recentArray
600 * An array of recently viewed or processed items, for in place modification.
604 public static function recent(&$recentArray) {
605 return self
::singleton()->invoke(1, $recentArray,
606 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
612 * Determine how many other records refer to a given record.
614 * @param CRM_Core_DAO $dao
615 * The item for which we want a reference count.
616 * @param array $refCounts
617 * Each item in the array is an Array with keys:
618 * - name: string, eg "sql:civicrm_email:contact_id"
619 * - type: string, eg "sql"
620 * - count: int, eg "5" if there are 5 email addresses that refer to $dao
623 * Return is not really intended to be used.
625 public static function referenceCounts($dao, &$refCounts) {
626 return self
::singleton()->invoke(2, $dao, $refCounts,
627 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
628 'civicrm_referenceCounts'
633 * This hook is called when building the amount structure for a Contribution or Event Page.
635 * @param int $pageType
636 * Is this a contribution or event page.
637 * @param CRM_Core_Form $form
638 * Reference to the form object.
639 * @param array $amount
640 * The amount structure to be displayed.
644 public static function buildAmount($pageType, &$form, &$amount) {
645 return self
::singleton()->invoke(3, $pageType, $form, $amount, self
::$_nullObject,
646 self
::$_nullObject, self
::$_nullObject, 'civicrm_buildAmount');
650 * This hook is called when building the state list for a particular country.
652 * @param array $countryID
653 * The country id whose states are being selected.
658 public static function buildStateProvinceForCountry($countryID, &$states) {
659 return self
::singleton()->invoke(2, $countryID, $states,
660 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
661 'civicrm_buildStateProvinceForCountry'
666 * This hook is called when rendering the tabs for a contact (q=civicrm/contact/view)c
669 * The array of tabs that will be displayed.
670 * @param int $contactID
671 * The contactID for whom the dashboard is being rendered.
674 * @deprecated Use tabset() instead.
676 public static function tabs(&$tabs, $contactID) {
677 return self
::singleton()->invoke(2, $tabs, $contactID,
678 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_tabs'
683 * This hook is called when rendering the tabs used for events and potentially
684 * contribution pages, etc.
686 * @param string $tabsetName
687 * Name of the screen or visual element.
689 * Tabs that will be displayed.
690 * @param array $context
691 * Extra data about the screen or context in which the tab is used.
695 public static function tabset($tabsetName, &$tabs, $context) {
696 return self
::singleton()->invoke(3, $tabsetName, $tabs,
697 $context, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_tabset'
702 * This hook is called when sending an email / printing labels
704 * @param array $tokens
705 * The list of tokens that can be used for the contact.
709 public static function tokens(&$tokens) {
710 return self
::singleton()->invoke(1, $tokens,
711 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_tokens'
716 * This hook is called when sending an email / printing labels to get the values for all the
717 * tokens returned by the 'tokens' hook
719 * @param array $details
720 * The array to store the token values indexed by contactIDs (unless it a single).
721 * @param array $contactIDs
722 * An array of contactIDs.
724 * The jobID if this is associated with a CiviMail mailing.
725 * @param array $tokens
726 * The list of tokens associated with the content.
727 * @param string $className
728 * The top level className from where the hook is invoked.
732 public static function tokenValues(
739 return self
::singleton()
740 ->invoke(5, $details, $contactIDs, $jobID, $tokens, $className, self
::$_nullObject, 'civicrm_tokenValues');
744 * This hook is called before a CiviCRM Page is rendered. You can use this hook to insert smarty variables
747 * @param object $page
748 * The page that will be rendered.
752 public static function pageRun(&$page) {
753 return self
::singleton()->invoke(1, $page,
754 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
760 * This hook is called after a copy of an object has been made. The current objects are
761 * Event, Contribution Page and UFGroup
763 * @param string $objectName
764 * Name of the object.
765 * @param object $object
766 * Reference to the copy.
770 public static function copy($objectName, &$object) {
771 return self
::singleton()->invoke(2, $objectName, $object,
772 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
778 * This hook is called when a contact unsubscribes from a mailing. It allows modules
779 * to override what the contacts are removed from.
783 * @param int $mailingId
784 * The id of the mailing to unsub from
785 * @param int $contactId
786 * The id of the contact who is unsubscribing
787 * @param array|int $groups
788 * Groups the contact will be removed from.
789 * @param array|int $baseGroups
790 * Base groups (used in smart mailings) the contact will be removed from.
795 public static function unsubscribeGroups($op, $mailingId, $contactId, &$groups, &$baseGroups) {
796 return self
::singleton()
797 ->invoke(5, $op, $mailingId, $contactId, $groups, $baseGroups, self
::$_nullObject, 'civicrm_unsubscribeGroups');
801 * This hook is called when CiviCRM needs to edit/display a custom field with options
803 * @deprecated in favor of hook_civicrm_fieldOptions
805 * @param int $customFieldID
806 * The custom field ID.
807 * @param array $options
808 * The current set of options for that custom field.
809 * You can add/remove existing options.
810 * Important: This array may contain meta-data about the field that is needed elsewhere, so it is important
811 * to be careful to not overwrite the array.
812 * Only add/edit/remove the specific field options you intend to affect.
813 * @param bool $detailedFormat
814 * If true, the options are in an ID => array ( 'id' => ID, 'label' => label, 'value' => value ) format
815 * @param array $selectAttributes
816 * Contain select attribute(s) if any.
820 public static function customFieldOptions($customFieldID, &$options, $detailedFormat = FALSE, $selectAttributes = array()) {
821 return self
::singleton()->invoke(3, $customFieldID, $options, $detailedFormat,
822 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
823 'civicrm_customFieldOptions'
828 * Hook for modifying field options
830 * @param string $entity
831 * @param string $field
832 * @param array $options
833 * @param array $params
837 public static function fieldOptions($entity, $field, &$options, $params) {
838 return self
::singleton()->invoke(5, $entity, $field, $options, $params,
839 self
::$_nullObject, self
::$_nullObject,
840 'civicrm_fieldOptions'
846 * This hook is called to display the list of actions allowed after doing a search.
847 * This allows the module developer to inject additional actions or to remove existing actions.
849 * @param string $objectType
850 * The object type for this search.
851 * - activity, campaign, case, contact, contribution, event, grant, membership, and pledge are supported.
852 * @param array $tasks
853 * The current set of tasks for that custom field.
854 * You can add/remove existing tasks.
855 * Each task needs to have a title (eg 'title' => ts( 'Group - add contacts')) and a class
856 * (eg 'class' => 'CRM_Contact_Form_Task_AddToGroup').
857 * Optional result (boolean) may also be provided. Class can be an array of classes (not sure what that does :( ).
858 * The key for new Task(s) should not conflict with the keys for core tasks of that $objectType, which can be
859 * found in CRM/$objectType/Task.php.
863 public static function searchTasks($objectType, &$tasks) {
864 return self
::singleton()->invoke(2, $objectType, $tasks,
865 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
866 'civicrm_searchTasks'
872 * @param array $params
876 public static function eventDiscount(&$form, &$params) {
877 return self
::singleton()->invoke(2, $form, $params,
878 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
879 'civicrm_eventDiscount'
884 * This hook is called when composing a mailing. You can include / exclude other groups as needed.
887 * The form object for which groups / mailings being displayed
888 * @param array $groups
889 * The list of groups being included / excluded
890 * @param array $mailings
891 * The list of mailings being included / excluded
895 public static function mailingGroups(&$form, &$groups, &$mailings) {
896 return self
::singleton()->invoke(3, $form, $groups, $mailings,
897 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
898 'civicrm_mailingGroups'
903 * (Experimental) Modify the list of template-types used for CiviMail composition.
905 * @param array $types
906 * Sequentially indexed list of template types. Each type specifies:
908 * - editorUrl: string, Angular template URL
909 * - weight: int, priority when picking a default value for new mailings
912 public static function mailingTemplateTypes(&$types) {
913 return self
::singleton()->invoke(1, $types, self
::$_nullObject, self
::$_nullObject,
914 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
915 'civicrm_mailingTemplateTypes'
920 * This hook is called when composing the array of membershipTypes and their cost during a membership registration
922 * Note the hook is called on initial page load and also reloaded after submit (PRG pattern).
923 * You can use it to alter the membership types when first loaded, or after submission
924 * (for example if you want to gather data in the form and use it to alter the fees).
927 * The form object that is presenting the page
928 * @param array $membershipTypes
929 * The array of membership types and their amount
933 public static function membershipTypeValues(&$form, &$membershipTypes) {
934 return self
::singleton()->invoke(2, $form, $membershipTypes,
935 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
936 'civicrm_membershipTypeValues'
941 * This hook is called when rendering the contact summary.
943 * @param int $contactID
944 * The contactID for whom the summary is being rendered
945 * @param mixed $content
946 * @param int $contentPlacement
947 * Specifies where the hook content should be displayed relative to the
951 * The html snippet to include in the contact summary
953 public static function summary($contactID, &$content, &$contentPlacement = self
::SUMMARY_BELOW
) {
954 return self
::singleton()->invoke(3, $contactID, $content, $contentPlacement,
955 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
961 * Use this hook to populate the list of contacts returned by Contact Reference custom fields.
962 * By default, Contact Reference fields will search on and return all CiviCRM contacts.
963 * If you want to limit the contacts returned to a specific group, or some other criteria
964 * - you can override that behavior by providing a SQL query that returns some subset of your contacts.
965 * The hook is called when the query is executed to get the list of contacts to display.
967 * @param mixed $query
968 * - the query that will be executed (input and output parameter);.
969 * It's important to realize that the ACL clause is built prior to this hook being fired,
970 * so your query will ignore any ACL rules that may be defined.
971 * Your query must return two columns:
972 * the contact 'data' to display in the autocomplete dropdown (usually contact.sort_name - aliased as 'data')
974 * @param string $name
975 * The name string to execute the query against (this is the value being typed in by the user).
976 * @param string $context
977 * The context in which this ajax call is being made (for example: 'customfield', 'caseview').
979 * The id of the object for which the call is being made.
980 * For custom fields, it will be the custom field id
984 public static function contactListQuery(&$query, $name, $context, $id) {
985 return self
::singleton()->invoke(4, $query, $name, $context, $id,
986 self
::$_nullObject, self
::$_nullObject,
987 'civicrm_contactListQuery'
992 * Hook definition for altering payment parameters before talking to a payment processor back end.
994 * Definition will look like this:
996 * function hook_civicrm_alterPaymentProcessorParams(
1002 * @param CRM_Core_Payment $paymentObj
1003 * Instance of payment class of the payment processor invoked (e.g., 'CRM_Core_Payment_Dummy')
1004 * See discussion in CRM-16224 as to whether $paymentObj should be passed by reference.
1005 * @param array &$rawParams
1006 * array of params as passed to to the processor
1007 * @param array &$cookedParams
1008 * params after the processor code has translated them into its own key/value pairs
1011 * This return is not really intended to be used.
1013 public static function alterPaymentProcessorParams(
1018 return self
::singleton()->invoke(3, $paymentObj, $rawParams, $cookedParams,
1019 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1020 'civicrm_alterPaymentProcessorParams'
1025 * This hook is called when an email is about to be sent by CiviCRM.
1027 * @param array $params
1028 * Array fields include: groupName, from, toName, toEmail, subject, cc, bcc, text, html,
1029 * returnPath, replyTo, headers, attachments (array)
1030 * @param string $context
1031 * The context in which the hook is being invoked, eg 'civimail'.
1035 public static function alterMailParams(&$params, $context = NULL) {
1036 return self
::singleton()->invoke(2, $params, $context,
1037 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1038 'civicrm_alterMailParams'
1043 * This hook is called when membership status is being calculated.
1045 * @param array $membershipStatus
1046 * Membership status details as determined - alter if required.
1047 * @param array $arguments
1048 * Arguments passed in to calculate date.
1053 * - 'exclude_is_admin'
1054 * - 'membership_type_id'
1055 * @param array $membership
1056 * Membership details from the calling function.
1060 public static function alterCalculatedMembershipStatus(&$membershipStatus, $arguments, $membership) {
1061 return self
::singleton()->invoke(3, $membershipStatus, $arguments,
1062 $membership, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1063 'civicrm_alterCalculatedMembershipStatus'
1068 * This hook is called after getting the content of the mail and before tokenizing it.
1070 * @param array $content
1071 * Array fields include: html, text, subject
1075 public static function alterMailContent(&$content) {
1076 return self
::singleton()->invoke(1, $content,
1077 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1078 'civicrm_alterMailContent'
1083 * This hook is called when rendering the Manage Case screen.
1085 * @param int $caseID
1089 * Array of data to be displayed, where the key is a unique id to be used for styling (div id's)
1090 * and the value is an array with keys 'label' and 'value' specifying label/value pairs
1092 public static function caseSummary($caseID) {
1093 return self
::singleton()->invoke(1, $caseID,
1094 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1095 'civicrm_caseSummary'
1100 * This hook is called when locating CiviCase types.
1102 * @param array $caseTypes
1106 public static function caseTypes(&$caseTypes) {
1107 return self
::singleton()
1108 ->invoke(1, $caseTypes, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_caseTypes');
1112 * This hook is called soon after the CRM_Core_Config object has ben initialized.
1113 * You can use this hook to modify the config object and hence behavior of CiviCRM dynamically.
1115 * @param CRM_Core_Config|array $config
1120 public static function config(&$config) {
1121 return self
::singleton()->invoke(1, $config,
1122 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1128 * This hooks allows to change option values.
1130 * @deprecated in favor of hook_civicrm_fieldOptions
1132 * @param array $options
1133 * Associated array of option values / id
1134 * @param string $name
1139 public static function optionValues(&$options, $name) {
1140 return self
::singleton()->invoke(2, $options, $name,
1141 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1142 'civicrm_optionValues'
1147 * This hook allows modification of the navigation menu.
1149 * @param array $params
1150 * Associated array of navigation menu entry to Modify/Add
1154 public static function navigationMenu(&$params) {
1155 return self
::singleton()->invoke(1, $params,
1156 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1157 'civicrm_navigationMenu'
1162 * This hook allows modification of the data used to perform merging of duplicates.
1164 * @param string $type
1165 * The type of data being passed (cidRefs|eidRefs|relTables|sqls).
1166 * @param array $data
1167 * The data, as described in $type.
1168 * @param int $mainId
1169 * Contact_id of the contact that survives the merge.
1170 * @param int $otherId
1171 * Contact_id of the contact that will be absorbed and deleted.
1172 * @param array $tables
1173 * When $type is "sqls", an array of tables as it may have been handed to the calling function.
1177 public static function merge($type, &$data, $mainId = NULL, $otherId = NULL, $tables = NULL) {
1178 return self
::singleton()->invoke(5, $type, $data, $mainId, $otherId, $tables, self
::$_nullObject, 'civicrm_merge');
1182 * This hook allows modification of the data calculated for merging locations.
1184 * @param array $blocksDAO
1185 * Array of location DAO to be saved. These are arrays in 2 keys 'update' & 'delete'.
1186 * @param int $mainId
1187 * Contact_id of the contact that survives the merge.
1188 * @param int $otherId
1189 * Contact_id of the contact that will be absorbed and deleted.
1190 * @param array $migrationInfo
1191 * Calculated migration info, informational only.
1195 public static function alterLocationMergeData(&$blocksDAO, $mainId, $otherId, $migrationInfo) {
1196 return self
::singleton()->invoke(4, $blocksDAO, $mainId, $otherId, $migrationInfo, self
::$_nullObject, self
::$_nullObject, 'civicrm_alterLocationMergeData');
1200 * This hook provides a way to override the default privacy behavior for notes.
1202 * @param array &$noteValues
1203 * Associative array of values for this note
1207 public static function notePrivacy(&$noteValues) {
1208 return self
::singleton()->invoke(1, $noteValues,
1209 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1210 'civicrm_notePrivacy'
1215 * This hook is called before record is exported as CSV.
1217 * @param string $exportTempTable
1218 * Name of the temporary export table used during export.
1219 * @param array $headerRows
1220 * Header rows for output.
1221 * @param array $sqlColumns
1223 * @param int $exportMode
1224 * Export mode ( contact, contribution, etc...).
1228 public static function export(&$exportTempTable, &$headerRows, &$sqlColumns, &$exportMode) {
1229 return self
::singleton()->invoke(4, $exportTempTable, $headerRows, $sqlColumns, $exportMode,
1230 self
::$_nullObject, self
::$_nullObject,
1236 * This hook allows modification of the queries constructed from dupe rules.
1238 * @param string $obj
1239 * Object of rulegroup class.
1240 * @param string $type
1241 * Type of queries e.g table / threshold.
1242 * @param array $query
1247 public static function dupeQuery($obj, $type, &$query) {
1248 return self
::singleton()->invoke(3, $obj, $type, $query,
1249 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1255 * This hook is called AFTER EACH email has been processed by the script bin/EmailProcessor.php
1257 * @param string $type
1258 * Type of mail processed: 'activity' OR 'mailing'.
1259 * @param array &$params the params that were sent to the CiviCRM API function
1260 * @param object $mail
1261 * The mail object which is an ezcMail class.
1262 * @param array &$result the result returned by the api call
1263 * @param string $action
1264 * (optional ) the requested action to be performed if the types was 'mailing'.
1268 public static function emailProcessor($type, &$params, $mail, &$result, $action = NULL) {
1269 return self
::singleton()
1270 ->invoke(5, $type, $params, $mail, $result, $action, self
::$_nullObject, 'civicrm_emailProcessor');
1274 * This hook is called after a row has been processed and the
1275 * record (and associated records imported
1277 * @param string $object
1278 * Object being imported (for now Contact only, later Contribution, Activity,.
1279 * Participant and Member)
1280 * @param string $usage
1281 * Hook usage/location (for now process only, later mapping and others).
1282 * @param string $objectRef
1283 * Import record object.
1284 * @param array $params
1285 * Array with various key values: currently.
1286 * contactID - contact id
1287 * importID - row id in temp table
1288 * importTempTable - name of tempTable
1289 * fieldHeaders - field headers
1290 * fields - import fields
1294 public static function import($object, $usage, &$objectRef, &$params) {
1295 return self
::singleton()->invoke(4, $object, $usage, $objectRef, $params,
1296 self
::$_nullObject, self
::$_nullObject,
1302 * This hook is called when API permissions are checked (cf. civicrm_api3_api_check_permission()
1303 * in api/v3/utils.php and _civicrm_api3_permissions() in CRM/Core/DAO/permissions.php).
1305 * @param string $entity
1306 * The API entity (like contact).
1307 * @param string $action
1308 * The API action (like get).
1309 * @param array &$params the API parameters
1310 * @param array &$permissions the associative permissions array (probably to be altered by this hook)
1314 public static function alterAPIPermissions($entity, $action, &$params, &$permissions) {
1315 return self
::singleton()->invoke(4, $entity, $action, $params, $permissions,
1316 self
::$_nullObject, self
::$_nullObject,
1317 'civicrm_alterAPIPermissions'
1322 * @param CRM_Core_DAO $dao
1326 public static function postSave(&$dao) {
1327 $hookName = 'civicrm_postSave_' . $dao->getTableName();
1328 return self
::singleton()->invoke(1, $dao,
1329 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1335 * This hook allows user to customize context menu Actions on contact summary page.
1337 * @param array $actions
1338 * Array of all Actions in contextmenu.
1339 * @param int $contactID
1340 * ContactID for the summary page.
1344 public static function summaryActions(&$actions, $contactID = NULL) {
1345 return self
::singleton()->invoke(2, $actions, $contactID,
1346 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1347 'civicrm_summaryActions'
1352 * This hook is called from CRM_Core_Selector_Controller through which all searches in civicrm go.
1353 * This enables us hook implementors to modify both the headers and the rows
1355 * The BIGGEST drawback with this hook is that you may need to modify the result template to include your
1356 * fields. The result files are CRM/{Contact,Contribute,Member,Event...}/Form/Selector.tpl
1358 * However, if you use the same number of columns, you can overwrite the existing columns with the values that
1359 * you want displayed. This is a hackish, but avoids template modification.
1361 * @param string $objectName
1362 * The component name that we are doing the search.
1363 * activity, campaign, case, contact, contribution, event, grant, membership, and pledge
1364 * @param array &$headers the list of column headers, an associative array with keys: ( name, sort, order )
1365 * @param array &$rows the list of values, an associate array with fields that are displayed for that component
1366 * @param array $selector
1367 * the selector object. Allows you access to the context of the search
1370 * modify the header and values object to pass the data you need
1372 public static function searchColumns($objectName, &$headers, &$rows, &$selector) {
1373 return self
::singleton()->invoke(4, $objectName, $headers, $rows, $selector,
1374 self
::$_nullObject, self
::$_nullObject,
1375 'civicrm_searchColumns'
1380 * This hook is called when uf groups are being built for a module.
1382 * @param string $moduleName
1384 * @param array $ufGroups
1385 * Array of ufgroups for a module.
1389 public static function buildUFGroupsForModule($moduleName, &$ufGroups) {
1390 return self
::singleton()->invoke(2, $moduleName, $ufGroups,
1391 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1392 'civicrm_buildUFGroupsForModule'
1397 * This hook is called when we are determining the contactID for a specific
1400 * @param string $email
1401 * The email address.
1402 * @param int $contactID
1403 * The contactID that matches this email address, IF it exists.
1404 * @param array $result
1405 * (reference) has two fields.
1406 * contactID - the new (or same) contactID
1407 * action - 3 possible values:
1408 * CRM_Utils_Mail_Incoming::EMAILPROCESSOR_CREATE_INDIVIDUAL - create a new contact record
1409 * CRM_Utils_Mail_Incoming::EMAILPROCESSOR_OVERRIDE - use the new contactID
1410 * CRM_Utils_Mail_Incoming::EMAILPROCESSOR_IGNORE - skip this email address
1414 public static function emailProcessorContact($email, $contactID, &$result) {
1415 return self
::singleton()->invoke(3, $email, $contactID, $result,
1416 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1417 'civicrm_emailProcessorContact'
1422 * Hook definition for altering the generation of Mailing Labels.
1424 * @param array $args
1425 * An array of the args in the order defined for the tcpdf multiCell api call.
1426 * with the variable names below converted into string keys (ie $w become 'w'
1427 * as the first key for $args)
1428 * float $w Width of cells. If 0, they extend up to the right margin of the page.
1429 * float $h Cell minimum height. The cell extends automatically if needed.
1430 * string $txt String to print
1431 * mixed $border Indicates if borders must be drawn around the cell block. The value can
1432 * be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or
1433 * a string containing some or all of the following characters (in any order):
1434 * <ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul>
1435 * string $align Allows to center or align the text. Possible values are:<ul><li>L or empty string:
1436 * left align</li><li>C: center</li><li>R: right align</li><li>J: justification
1437 * (default value when $ishtml=false)</li></ul>
1438 * int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
1439 * int $ln Indicates where the current position should go after the call. Possible values are:<ul><li>0:
1440 * to the right</li><li>1: to the beginning of the next line [DEFAULT]</li><li>2: below</li></ul>
1441 * float $x x position in user units
1442 * float $y y position in user units
1443 * boolean $reseth if true reset the last cell height (default true).
1444 * int $stretch stretch character mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if
1445 * necessary</li><li>2 = forced horizontal scaling</li><li>3 = character spacing only if
1446 * necessary</li><li>4 = forced character spacing</li></ul>
1447 * boolean $ishtml set to true if $txt is HTML content (default = false).
1448 * boolean $autopadding if true, uses internal padding and automatically adjust it to account for line width.
1449 * float $maxh maximum height. It should be >= $h and less then remaining space to the bottom of the page,
1450 * or 0 for disable this feature. This feature works only when $ishtml=false.
1454 public static function alterMailingLabelParams(&$args) {
1455 return self
::singleton()->invoke(1, $args,
1456 self
::$_nullObject, self
::$_nullObject,
1457 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1458 'civicrm_alterMailingLabelParams'
1463 * This hooks allows alteration of generated page content.
1466 * Previously generated content.
1468 * Context of content - page or form.
1470 * The file name of the tpl.
1472 * A reference to the page or form object.
1476 public static function alterContent(&$content, $context, $tplName, &$object) {
1477 return self
::singleton()->invoke(4, $content, $context, $tplName, $object,
1478 self
::$_nullObject, self
::$_nullObject,
1479 'civicrm_alterContent'
1484 * This hooks allows alteration of the tpl file used to generate content. It differs from the
1485 * altercontent hook as the content has already been rendered through the tpl at that point
1488 * Previously generated content.
1490 * Reference to the form object.
1492 * Context of content - page or form.
1494 * Reference the file name of the tpl.
1498 public static function alterTemplateFile($formName, &$form, $context, &$tplName) {
1499 return self
::singleton()->invoke(4, $formName, $form, $context, $tplName,
1500 self
::$_nullObject, self
::$_nullObject,
1501 'civicrm_alterTemplateFile'
1506 * This hook collects the trigger definition from all components.
1509 * @param string $tableName
1510 * (optional) the name of the table that we are interested in only.
1512 * @internal param \reference $triggerInfo to an array of trigger information
1513 * each element has 4 fields:
1514 * table - array of tableName
1515 * when - BEFORE or AFTER
1516 * event - array of eventName - INSERT OR UPDATE OR DELETE
1517 * sql - array of statements optionally terminated with a ;
1518 * a statement can use the tokes {tableName} and {eventName}
1519 * to do token replacement with the table / event. This allows
1520 * templatizing logging and other hooks
1523 public static function triggerInfo(&$info, $tableName = NULL) {
1524 return self
::singleton()->invoke(2, $info, $tableName,
1525 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1527 'civicrm_triggerInfo'
1531 * This hook allows changes to the spec of which tables to log.
1533 * @param array $logTableSpec
1537 public static function alterLogTables(&$logTableSpec) {
1538 return self
::singleton()->invoke(1, $logTableSpec, $_nullObject,
1539 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1541 'civicrm_alterLogTables'
1546 * This hook is called when a module-extension is installed.
1547 * Each module will receive hook_civicrm_install during its own installation (but not during the
1548 * installation of unrelated modules).
1550 public static function install() {
1551 return self
::singleton()->invoke(0, self
::$_nullObject,
1552 self
::$_nullObject, self
::$_nullObject,
1553 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1559 * This hook is called when a module-extension is uninstalled.
1560 * Each module will receive hook_civicrm_uninstall during its own uninstallation (but not during the
1561 * uninstallation of unrelated modules).
1563 public static function uninstall() {
1564 return self
::singleton()->invoke(0, self
::$_nullObject,
1565 self
::$_nullObject, self
::$_nullObject,
1566 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1572 * This hook is called when a module-extension is re-enabled.
1573 * Each module will receive hook_civicrm_enable during its own re-enablement (but not during the
1574 * re-enablement of unrelated modules).
1576 public static function enable() {
1577 return self
::singleton()->invoke(0, self
::$_nullObject,
1578 self
::$_nullObject, self
::$_nullObject,
1579 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1585 * This hook is called when a module-extension is disabled.
1586 * Each module will receive hook_civicrm_disable during its own disablement (but not during the
1587 * disablement of unrelated modules).
1589 public static function disable() {
1590 return self
::singleton()->invoke(0, self
::$_nullObject,
1591 self
::$_nullObject, self
::$_nullObject,
1592 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1604 public static function alterReportVar($varType, &$var, &$object) {
1605 return self
::singleton()->invoke(3, $varType, $var, $object,
1607 self
::$_nullObject, self
::$_nullObject,
1608 'civicrm_alterReportVar'
1613 * This hook is called to drive database upgrades for extension-modules.
1616 * The type of operation being performed; 'check' or 'enqueue'.
1617 * @param CRM_Queue_Queue $queue
1618 * (for 'enqueue') the modifiable list of pending up upgrade tasks.
1621 * NULL, if $op is 'enqueue'.
1622 * TRUE, if $op is 'check' and upgrades are pending.
1623 * FALSE, if $op is 'check' and upgrades are not pending.
1625 public static function upgrade($op, CRM_Queue_Queue
$queue = NULL) {
1626 return self
::singleton()->invoke(2, $op, $queue,
1627 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1634 * This hook is called when an email has been successfully sent by CiviCRM, but not on an error.
1636 * @param array $params
1637 * The mailing parameters. Array fields include: groupName, from, toName,
1638 * toEmail, subject, cc, bcc, text, html, returnPath, replyTo, headers,
1639 * attachments (array)
1643 public static function postEmailSend(&$params) {
1644 return self
::singleton()->invoke(1, $params,
1645 self
::$_nullObject, self
::$_nullObject,
1646 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1647 'civicrm_postEmailSend'
1652 * This hook is called when a CiviMail mailing has completed
1654 * @param int $mailingId
1659 public static function postMailing($mailingId) {
1660 return self
::singleton()->invoke(1, $mailingId,
1661 self
::$_nullObject, self
::$_nullObject,
1662 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1663 'civicrm_postMailing'
1668 * This hook is called when Settings specifications are loaded.
1670 * @param array $settingsFolders
1671 * List of paths from which to derive metadata
1675 public static function alterSettingsFolders(&$settingsFolders) {
1676 return self
::singleton()->invoke(1, $settingsFolders,
1677 self
::$_nullObject, self
::$_nullObject,
1678 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1679 'civicrm_alterSettingsFolders'
1684 * This hook is called when Settings have been loaded from the xml
1685 * It is an opportunity for hooks to alter the data
1687 * @param array $settingsMetaData
1688 * Settings Metadata.
1689 * @param int $domainID
1690 * @param mixed $profile
1694 public static function alterSettingsMetaData(&$settingsMetaData, $domainID, $profile) {
1695 return self
::singleton()->invoke(3, $settingsMetaData,
1696 $domainID, $profile,
1697 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1698 'civicrm_alterSettingsMetaData'
1703 * This hook is called before running an api call.
1705 * @param API_Wrapper[] $wrappers
1706 * (see CRM_Utils_API_ReloadOption as an example)
1707 * @param mixed $apiRequest
1710 * The return value is ignored
1712 public static function apiWrappers(&$wrappers, $apiRequest) {
1713 return self
::singleton()
1714 ->invoke(2, $wrappers, $apiRequest, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1715 self
::$_nullObject, 'civicrm_apiWrappers'
1720 * This hook is called before running pending cron jobs.
1722 * @param CRM_Core_JobManager $jobManager
1725 * The return value is ignored.
1727 public static function cron($jobManager) {
1728 return self
::singleton()->invoke(1,
1729 $jobManager, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1735 * This hook is called when loading CMS permissions; use this hook to modify
1736 * the array of system permissions for CiviCRM.
1738 * @param array $permissions
1739 * Array of permissions. See CRM_Core_Permission::getCorePermissions() for
1740 * the format of this array.
1743 * The return value is ignored
1745 public static function permission(&$permissions) {
1746 return self
::singleton()->invoke(1, $permissions,
1747 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1748 'civicrm_permission'
1753 * @param CRM_Core_Exception Exception $exception
1754 * @param mixed $request
1755 * Reserved for future use.
1757 public static function unhandledException($exception, $request = NULL) {
1759 ->invoke(2, $exception, $request, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_unhandled_exception');
1761 // $event = new stdClass();
1762 // $event->exception = $exception;
1763 // CRM_Core_LegacyErrorHandler::handleException($event);
1766 $event = new \Civi\Core\Event\
UnhandledExceptionEvent($exception, self
::$_nullObject);
1767 \Civi
::service('dispatcher')->dispatch("hook_civicrm_unhandled_exception", $event);
1771 * This hook is called for declaring managed entities via API.
1773 * @param array[] $entityTypes
1774 * List of entity types; each entity-type is an array with keys:
1775 * - name: string, a unique short name (e.g. "ReportInstance")
1776 * - class: string, a PHP DAO class (e.g. "CRM_Report_DAO_Instance")
1777 * - table: string, a SQL table name (e.g. "civicrm_report_instance")
1778 * - fields_callback: array, list of callables which manipulates field list
1779 * - links_callback: array, list of callables which manipulates fk list
1782 * The return value is ignored
1784 public static function entityTypes(&$entityTypes) {
1785 return self
::singleton()->invoke(1, $entityTypes, self
::$_nullObject, self
::$_nullObject,
1786 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_entityTypes'
1791 * This hook is called while preparing a profile form.
1793 * @param string $name
1796 public static function buildProfile($name) {
1797 return self
::singleton()->invoke(1, $name, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1798 self
::$_nullObject, self
::$_nullObject, 'civicrm_buildProfile');
1802 * This hook is called while validating a profile form submission.
1804 * @param string $name
1807 public static function validateProfile($name) {
1808 return self
::singleton()->invoke(1, $name, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1809 self
::$_nullObject, self
::$_nullObject, 'civicrm_validateProfile');
1813 * This hook is called processing a valid profile form submission.
1815 * @param string $name
1818 public static function processProfile($name) {
1819 return self
::singleton()->invoke(1, $name, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1820 self
::$_nullObject, self
::$_nullObject, 'civicrm_processProfile');
1824 * This hook is called while preparing a read-only profile screen
1826 * @param string $name
1829 public static function viewProfile($name) {
1830 return self
::singleton()->invoke(1, $name, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1831 self
::$_nullObject, self
::$_nullObject, 'civicrm_viewProfile');
1835 * This hook is called while preparing a list of contacts (based on a profile)
1837 * @param string $name
1840 public static function searchProfile($name) {
1841 return self
::singleton()->invoke(1, $name, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1842 self
::$_nullObject, self
::$_nullObject, 'civicrm_searchProfile');
1846 * This hook is invoked when building a CiviCRM name badge.
1848 * @param string $labelName
1849 * String referencing name of badge format.
1850 * @param object $label
1851 * Reference to the label object.
1852 * @param array $format
1853 * Array of format data.
1854 * @param array $participant
1855 * Array of participant values.
1858 * the return value is ignored
1860 public static function alterBadge($labelName, &$label, &$format, &$participant) {
1861 return self
::singleton()
1862 ->invoke(4, $labelName, $label, $format, $participant, self
::$_nullObject, self
::$_nullObject, 'civicrm_alterBadge');
1867 * This hook is called before encoding data in barcode.
1869 * @param array $data
1870 * Associated array of values available for encoding.
1871 * @param string $type
1872 * Type of barcode, classic barcode or QRcode.
1873 * @param string $context
1874 * Where this hooks is invoked.
1878 public static function alterBarcode(&$data, $type = 'barcode', $context = 'name_badge') {
1879 return self
::singleton()->invoke(3, $data, $type, $context, self
::$_nullObject,
1880 self
::$_nullObject, self
::$_nullObject, 'civicrm_alterBarcode');
1884 * Modify or replace the Mailer object used for outgoing mail.
1886 * @param object $mailer
1887 * The default mailer produced by normal configuration; a PEAR "Mail" class (like those returned by Mail::factory)
1888 * @param string $driver
1889 * The type of the default mailer (eg "smtp", "sendmail", "mock", "CRM_Mailing_BAO_Spool")
1890 * @param array $params
1891 * The default mailer config options
1894 * @see Mail::factory
1896 public static function alterMailer(&$mailer, $driver, $params) {
1897 return self
::singleton()
1898 ->invoke(3, $mailer, $driver, $params, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_alterMailer');
1902 * Deprecated: Misnamed version of alterMailer(). Remove post-4.7.x.
1903 * Modify or replace the Mailer object used for outgoing mail.
1905 * @param object $mailer
1906 * The default mailer produced by normal configuration; a PEAR "Mail" class (like those returned by Mail::factory)
1907 * @param string $driver
1908 * The type of the default mailer (eg "smtp", "sendmail", "mock", "CRM_Mailing_BAO_Spool")
1909 * @param array $params
1910 * The default mailer config options
1913 * @see Mail::factory
1916 public static function alterMail(&$mailer, $driver, $params) {
1917 return CRM_Utils_Hook
::alterMailer($mailer, $driver, $params);
1921 * This hook is called while building the core search query,
1922 * so hook implementers can provide their own query objects which alters/extends core search.
1924 * @param array $queryObjects
1925 * @param string $type
1929 public static function queryObjects(&$queryObjects, $type = 'Contact') {
1930 return self
::singleton()
1931 ->invoke(2, $queryObjects, $type, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_queryObjects');
1935 * This hook is called while viewing contact dashboard.
1937 * @param array $availableDashlets
1938 * List of dashlets; each is formatted per api/v3/Dashboard
1939 * @param array $defaultDashlets
1940 * List of dashlets; each is formatted per api/v3/DashboardContact
1944 public static function dashboard_defaults($availableDashlets, &$defaultDashlets) {
1945 return self
::singleton()
1946 ->invoke(2, $availableDashlets, $defaultDashlets, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_dashboard_defaults');
1950 * This hook is called before a case merge (or a case reassign)
1952 * @param int $mainContactId
1953 * @param int $mainCaseId
1954 * @param int $otherContactId
1955 * @param int $otherCaseId
1956 * @param bool $changeClient
1960 public static function pre_case_merge($mainContactId, $mainCaseId = NULL, $otherContactId = NULL, $otherCaseId = NULL, $changeClient = FALSE) {
1961 return self
::singleton()
1962 ->invoke(5, $mainContactId, $mainCaseId, $otherContactId, $otherCaseId, $changeClient, self
::$_nullObject, 'civicrm_pre_case_merge');
1966 * This hook is called after a case merge (or a case reassign)
1968 * @param int $mainContactId
1969 * @param int $mainCaseId
1970 * @param int $otherContactId
1971 * @param int $otherCaseId
1972 * @param bool $changeClient
1976 public static function post_case_merge($mainContactId, $mainCaseId = NULL, $otherContactId = NULL, $otherCaseId = NULL, $changeClient = FALSE) {
1977 return self
::singleton()
1978 ->invoke(5, $mainContactId, $mainCaseId, $otherContactId, $otherCaseId, $changeClient, self
::$_nullObject, 'civicrm_post_case_merge');
1983 * Add a hook for altering the display name
1985 * hook_civicrm_contact_get_displayname(&$display_name, $objContact)
1987 * @param string $displayName
1988 * @param int $contactId
1989 * @param object $dao
1990 * The contact object.
1994 public static function alterDisplayName(&$displayName, $contactId, $dao) {
1995 return self
::singleton()->invoke(3,
1996 $displayName, $contactId, $dao, self
::$_nullObject, self
::$_nullObject,
1997 self
::$_nullObject, 'civicrm_contact_get_displayname'
2002 * EXPERIMENTAL: This hook allows one to register additional Angular modules
2004 * @param array $angularModules
2007 * the return value is ignored
2010 * function mymod_civicrm_angularModules(&$angularModules) {
2011 * $angularModules['myAngularModule'] = array(
2012 * 'ext' => 'org.example.mymod',
2013 * 'js' => array('js/myAngularModule.js'),
2015 * $angularModules['myBigAngularModule'] = array(
2016 * 'ext' => 'org.example.mymod',
2017 * 'js' => array('js/part1.js', 'js/part2.js'),
2018 * 'css' => array('css/myAngularModule.css'),
2019 * 'partials' => array('partials/myBigAngularModule'),
2024 public static function angularModules(&$angularModules) {
2025 return self
::singleton()->invoke(1, $angularModules,
2026 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
2027 'civicrm_angularModules'
2032 * This hook fires whenever a record in a case changes.
2034 * @param \Civi\CCase\Analyzer $analyzer
2035 * A bundle of data about the case (such as the case and activity records).
2037 public static function caseChange(\Civi\CCase\Analyzer
$analyzer) {
2038 $event = new \Civi\CCase\Event\
CaseChangeEvent($analyzer);
2039 \Civi
::service('dispatcher')->dispatch("hook_civicrm_caseChange", $event);
2041 self
::singleton()->invoke(1, $analyzer,
2042 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
2043 'civicrm_caseChange'
2048 * Generate a default CRUD URL for an entity.
2050 * @param array $spec
2052 * - action: int, eg CRM_Core_Action::VIEW or CRM_Core_Action::UPDATE
2053 * - entity_table: string
2055 * @param CRM_Core_DAO $bao
2056 * @param array $link
2057 * To define the link, add these keys to $link:.
2061 * - url: string (used in lieu of "path"/"query")
2062 * Note: if making "url" CRM_Utils_System::url(), set $htmlize=false
2065 public static function crudLink($spec, $bao, &$link) {
2066 return self
::singleton()->invoke(3, $spec, $bao, $link,
2067 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
2073 * Modify the CiviCRM container - add new services, parameters, extensions, etc.
2076 * use Symfony\Component\Config\Resource\FileResource;
2077 * use Symfony\Component\DependencyInjection\Definition;
2079 * function mymodule_civicrm_container($container) {
2080 * $container->addResource(new FileResource(__FILE__));
2081 * $container->setDefinition('mysvc', new Definition('My\Class', array()));
2085 * Tip: The container configuration will be compiled/cached. The default cache
2086 * behavior is aggressive. When you first implement the hook, be sure to
2087 * flush the cache. Additionally, you should relax caching during development.
2088 * In `civicrm.settings.php`, set define('CIVICRM_CONTAINER_CACHE', 'auto').
2090 * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
2091 * @see http://symfony.com/doc/current/components/dependency_injection/index.html
2093 public static function container(\Symfony\Component\DependencyInjection\ContainerBuilder
$container) {
2094 self
::singleton()->invoke(1, $container, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_container');
2098 * @param array <CRM_Core_FileSearchInterface> $fileSearches
2101 public static function fileSearches(&$fileSearches) {
2102 return self
::singleton()->invoke(1, $fileSearches,
2103 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
2104 'civicrm_fileSearches'
2109 * Check system status.
2111 * @param array $messages
2112 * Array<CRM_Utils_Check_Message>. A list of messages regarding system status.
2115 public static function check(&$messages) {
2116 return self
::singleton()
2117 ->invoke(1, $messages, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_check');
2121 * This hook is called when a query string of the CSV Batch export is generated.
2123 * @param string $query
2127 public static function batchQuery(&$query) {
2128 return self
::singleton()->invoke(1, $query, self
::$_nullObject,
2129 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
2130 'civicrm_batchQuery'
2135 * This hook is called to alter Deferred revenue item values just before they are
2136 * inserted in civicrm_financial_trxn table
2138 * @param array $deferredRevenues
2140 * @param array $contributionDetails
2142 * @param bool $update
2144 * @param string $context
2148 public static function alterDeferredRevenueItems(&$deferredRevenues, $contributionDetails, $update, $context) {
2149 return self
::singleton()->invoke(4, $deferredRevenues, $contributionDetails, $update, $context,
2150 self
::$_nullObject, self
::$_nullObject, 'civicrm_alterDeferredRevenueItems'
2155 * This hook is called when the entries of the CSV Batch export are mapped.
2157 * @param array $results
2158 * @param array $items
2162 public static function batchItems(&$results, &$items) {
2163 return self
::singleton()->invoke(2, $results, $items,
2164 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
2165 'civicrm_batchItems'
2170 * This hook is called when core resources are being loaded
2172 * @see CRM_Core_Resources::coreResourceList
2174 * @param array $list
2175 * @param string $region
2177 public static function coreResourceList(&$list, $region) {
2178 // First allow the cms integration to add to the list
2179 CRM_Core_Config
::singleton()->userSystem
->appendCoreResources($list);
2181 self
::singleton()->invoke(2, $list, $region,
2182 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
2183 'civicrm_coreResourceList'
2188 * Allows the list of filters on the EntityRef widget to be altered.
2190 * @see CRM_Core_Resources::entityRefFilters
2192 * @param array $filters
2194 public static function entityRefFilters(&$filters) {
2195 self
::singleton()->invoke(1, $filters, self
::$_nullObject, self
::$_nullObject,
2196 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
2197 'civicrm_entityRefFilters'
2202 * This hook is called for bypass a few civicrm urls from IDS check.
2204 * @param array $skip list of civicrm urls
2208 public static function idsException(&$skip) {
2209 return self
::singleton()->invoke(1, $skip, self
::$_nullObject,
2210 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
2211 'civicrm_idsException'
2216 * This hook is called when a geocoder's format method is called.
2218 * @param string $geoProvider
2219 * @param array $values
2220 * @param SimpleXMLElement $xml
2224 public static function geocoderFormat($geoProvider, &$values, $xml) {
2225 return self
::singleton()->invoke(3, $geoProvider, $values, $xml,
2226 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
2227 'civicrm_geocoderFormat'