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'),
104 * Invoke a hook through the UF/CMS hook system and the extension-hook
107 * @param int $numParams
108 * Number of parameters to pass to the hook.
110 * Parameter to be passed to the hook.
112 * Parameter to be passed to the hook.
114 * Parameter to be passed to the hook.
116 * Parameter to be passed to the hook.
118 * Parameter to be passed to the hook.
120 * Parameter to be passed to the hook.
121 * @param string $fnSuffix
122 * Function suffix, this is effectively the hook name.
126 public abstract function invokeViaUF(
128 &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6,
135 * This is a transitional adapter. It supports the legacy syntax
136 * but also accepts enough information to support Symfony Event
139 * @param array|int $names
140 * (Recommended) Array of parameter names, in order.
141 * Using an array is recommended because it enables full
142 * event-broadcasting behaviors.
143 * (Legacy) Number of parameters to pass to the hook.
144 * This is provided for transitional purposes.
151 * @param mixed $fnSuffix
154 public function invoke(
156 &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6,
159 if (is_array($names) && !defined('CIVICRM_FORCE_LEGACY_HOOK') && \Civi\Core\Container
::isContainerBooted()) {
160 $event = \Civi\Core\Event\GenericHookEvent
::createOrdered(
162 array(&$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6)
164 \Civi
::dispatcher()->dispatch('hook_' . $fnSuffix, $event);
165 return $event->getReturnValues();
168 $count = is_array($names) ?
count($names) : $names;
169 return $this->invokeViaUF($count, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $fnSuffix);
174 * @param array $numParams
186 public function commonInvoke(
188 &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6,
192 $this->commonBuildModuleList($fnPrefix);
194 return $this->runHooks($this->commonCiviModules
, $fnSuffix,
195 $numParams, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6
200 * Build the list of modules to be processed for hooks.
202 * @param string $fnPrefix
204 public function commonBuildModuleList($fnPrefix) {
205 if (!$this->commonIncluded
) {
206 // include external file
207 $this->commonIncluded
= TRUE;
209 $config = CRM_Core_Config
::singleton();
210 if (!empty($config->customPHPPathDir
) &&
211 file_exists("{$config->customPHPPathDir}/civicrmHooks.php")
213 @include_once
"civicrmHooks.php";
216 if (!empty($fnPrefix)) {
217 $this->commonCiviModules
[$fnPrefix] = $fnPrefix;
220 $this->requireCiviModules($this->commonCiviModules
);
225 * @param $civiModules
227 * @param array $numParams
237 public function runHooks(
238 $civiModules, $fnSuffix, $numParams,
239 &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6
241 // $civiModules is *not* passed by reference because runHooks
242 // must be reentrant. PHP is finicky about running
243 // multiple loops over the same variable. The circumstances
244 // to reproduce the issue are pretty intricate.
247 $fnNames = $this->cache
->get($fnSuffix);
248 if (!is_array($fnNames)) {
250 if ($civiModules !== NULL) {
251 foreach ($civiModules as $module) {
252 $fnName = "{$module}_{$fnSuffix}";
253 if (function_exists($fnName)) {
254 $fnNames[] = $fnName;
257 $this->cache
->set($fnSuffix, $fnNames);
261 foreach ($fnNames as $fnName) {
263 switch ($numParams) {
265 $fResult = $fnName();
269 $fResult = $fnName($arg1);
273 $fResult = $fnName($arg1, $arg2);
277 $fResult = $fnName($arg1, $arg2, $arg3);
281 $fResult = $fnName($arg1, $arg2, $arg3, $arg4);
285 $fResult = $fnName($arg1, $arg2, $arg3, $arg4, $arg5);
289 $fResult = $fnName($arg1, $arg2, $arg3, $arg4, $arg5, $arg6);
293 CRM_Core_Error
::fatal(ts('Invalid hook invocation'));
297 if (!empty($fResult) &&
300 $result = array_merge($result, $fResult);
304 return empty($result) ?
TRUE : $result;
310 public function requireCiviModules(&$moduleList) {
311 $civiModules = CRM_Core_PseudoConstant
::getModuleExtensions();
312 foreach ($civiModules as $civiModule) {
313 if (!file_exists($civiModule['filePath'])) {
314 CRM_Core_Session
::setStatus(
315 ts('Error loading module file (%1). Please restore the file or disable the module.',
316 array(1 => $civiModule['filePath'])),
317 ts('Warning'), 'error');
320 include_once $civiModule['filePath'];
321 $moduleList[$civiModule['prefix']] = $civiModule['prefix'];
326 * This hook is called before a db write on some core objects.
327 * This hook does not allow the abort of the operation
330 * The type of operation being performed.
331 * @param string $objectName
332 * The name of the object.
334 * The object id if available.
335 * @param array $params
336 * The parameters used for object creation / editing.
339 * the return value is ignored
341 public static function pre($op, $objectName, $id, &$params) {
342 $event = new \Civi\Core\Event\
PreEvent($op, $objectName, $id, $params);
343 \Civi
::dispatcher()->dispatch('hook_civicrm_pre', $event);
344 return $event->getReturnValues();
348 * This hook is called after a db write on some core objects.
351 * The type of operation being performed.
352 * @param string $objectName
353 * The name of the object.
354 * @param int $objectId
355 * The unique identifier for the object.
356 * @param object $objectRef
357 * The reference to the object if available.
360 * based on op. pre-hooks return a boolean or
361 * an error message which aborts the operation
363 public static function post($op, $objectName, $objectId, &$objectRef = NULL) {
364 $event = new \Civi\Core\Event\
PostEvent($op, $objectName, $objectId, $objectRef);
365 \Civi
::dispatcher()->dispatch('hook_civicrm_post', $event);
366 return $event->getReturnValues();
370 * This hook retrieves links from other modules and injects it into.
371 * the view contact tabs
374 * The type of operation being performed.
375 * @param string $objectName
376 * The name of the object.
377 * @param int $objectId
378 * The unique identifier for the object.
379 * @param array $links
380 * (optional) the links array (introduced in v3.2).
382 * (optional) the bitmask to show/hide links.
383 * @param array $values
384 * (optional) the values to fill the links.
387 * the return value is ignored
389 public static function links($op, $objectName, &$objectId, &$links, &$mask = NULL, &$values = array()) {
390 return self
::singleton()->invoke(array('op', 'objectName', 'objectId', 'links', 'mask', 'values'), $op, $objectName, $objectId, $links, $mask, $values, 'civicrm_links');
394 * This hook is invoked during the CiviCRM form preProcess phase.
396 * @param string $formName
397 * The name of the form.
398 * @param CRM_Core_Form $form
399 * Reference to the form object.
402 * the return value is ignored
404 public static function preProcess($formName, &$form) {
405 return self
::singleton()
406 ->invoke(array('formName', 'form'), $formName, $form, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_preProcess');
410 * This hook is invoked when building a CiviCRM form. This hook should also
411 * be used to set the default values of a form element
413 * @param string $formName
414 * The name of the form.
415 * @param CRM_Core_Form $form
416 * Reference to the form object.
419 * the return value is ignored
421 public static function buildForm($formName, &$form) {
422 return self
::singleton()->invoke(array('formName', 'form'), $formName, $form,
423 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
429 * This hook is invoked when a CiviCRM form is submitted. If the module has injected
430 * any form elements, this hook should save the values in the database
432 * @param string $formName
433 * The name of the form.
434 * @param CRM_Core_Form $form
435 * Reference to the form object.
438 * the return value is ignored
440 public static function postProcess($formName, &$form) {
441 return self
::singleton()->invoke(array('formName', 'form'), $formName, $form,
442 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
443 'civicrm_postProcess'
448 * This hook is invoked during all CiviCRM form validation. An array of errors
449 * detected is returned. Else we assume validation succeeded.
451 * @param string $formName
452 * The name of the form.
453 * @param array &$fields the POST parameters as filtered by QF
454 * @param array &$files the FILES parameters as sent in by POST
455 * @param array &$form the form object
456 * @param array &$errors the array of errors.
459 * formRule hooks return a boolean or
460 * an array of error messages which display a QF Error
462 public static function validateForm($formName, &$fields, &$files, &$form, &$errors) {
463 return self
::singleton()
464 ->invoke(array('formName', 'fields', 'files', 'form', 'errors'),
465 $formName, $fields, $files, $form, $errors, self
::$_nullObject, 'civicrm_validateForm');
469 * This hook is called after a db write on a custom table.
472 * The type of operation being performed.
473 * @param string $groupID
474 * The custom group ID.
475 * @param object $entityID
476 * The entityID of the row in the custom table.
477 * @param array $params
478 * The parameters that were sent into the calling function.
481 * the return value is ignored
483 public static function custom($op, $groupID, $entityID, &$params) {
484 return self
::singleton()
485 ->invoke(array('op', 'groupID', 'entityID', 'params'), $op, $groupID, $entityID, $params, self
::$_nullObject, self
::$_nullObject, 'civicrm_custom');
489 * This hook is called when composing the ACL where clause to restrict
490 * visibility of contacts to the logged in user
493 * The type of permission needed.
494 * @param array $tables
495 * (reference ) add the tables that are needed for the select clause.
496 * @param array $whereTables
497 * (reference ) add the tables that are needed for the where clause.
498 * @param int $contactID
499 * The contactID for whom the check is made.
500 * @param string $where
501 * The currrent where clause.
504 * the return value is ignored
506 public static function aclWhereClause($type, &$tables, &$whereTables, &$contactID, &$where) {
507 return self
::singleton()
508 ->invoke(array('type', 'tables', 'whereTables', 'contactID', 'where'), $type, $tables, $whereTables, $contactID, $where, self
::$_nullObject, 'civicrm_aclWhereClause');
512 * This hook is called when composing the ACL where clause to restrict
513 * visibility of contacts to the logged in user
516 * The type of permission needed.
517 * @param int $contactID
518 * The contactID for whom the check is made.
519 * @param string $tableName
520 * The tableName which is being permissioned.
521 * @param array $allGroups
522 * The set of all the objects for the above table.
523 * @param array $currentGroups
524 * The set of objects that are currently permissioned for this contact.
527 * the return value is ignored
529 public static function aclGroup($type, $contactID, $tableName, &$allGroups, &$currentGroups) {
530 return self
::singleton()
531 ->invoke(array('type', 'contactID', 'tableName', 'allGroups', 'currentGroups'), $type, $contactID, $tableName, $allGroups, $currentGroups, self
::$_nullObject, 'civicrm_aclGroup');
535 * @param string|CRM_Core_DAO $entity
536 * @param array $clauses
539 public static function selectWhereClause($entity, &$clauses) {
540 $entityName = is_object($entity) ?
_civicrm_api_get_entity_name_from_dao($entity) : $entity;
541 return self
::singleton()->invoke(array('entity', 'clauses'), $entityName, $clauses,
542 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
543 'civicrm_selectWhereClause'
548 * This hook is called when building the menu table.
550 * @param array $files
551 * The current set of files to process.
554 * the return value is ignored
556 public static function xmlMenu(&$files) {
557 return self
::singleton()->invoke(array('files'), $files,
558 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
564 * (Experimental) This hook is called when build the menu table.
566 * @param array $items
567 * List of records to include in menu table.
569 * the return value is ignored
571 public static function alterMenu(&$items) {
572 return self
::singleton()->invoke(array('items'), $items,
573 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
579 * This hook is called for declaring managed entities via API.
581 * @param array $entities
582 * List of pending entities. Each entity is an array with keys:
583 * + '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")
584 * + 'name': string, a symbolic name which can be used to track this entity (Note: Each module creates its own namespace)
585 * + 'entity': string, an entity-type supported by the CiviCRM API (Note: this currently must be an entity which supports the 'is_active' property)
586 * + 'params': array, the entity data as supported by the CiviCRM API
587 * + 'update' (v4.5+): string, a policy which describes when to update records
588 * - 'always' (default): always update the managed-entity record; changes in $entities will override any local changes (eg by the site-admin)
589 * - 'never': never update the managed-entity record; changes made locally (eg by the site-admin) will override changes in $entities
590 * + '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)
591 * - 'always' (default): always delete orphaned records
592 * - 'never': never delete orphaned records
593 * - '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.)
596 * the return value is ignored
598 public static function managed(&$entities) {
599 return self
::singleton()->invoke(array('entities'), $entities,
600 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
606 * This hook is called when rendering the dashboard (q=civicrm/dashboard)
608 * @param int $contactID
609 * The contactID for whom the dashboard is being rendered.
610 * @param int $contentPlacement
611 * (output parameter) where should the hook content be displayed.
612 * relative to the activity list
615 * the html snippet to include in the dashboard
617 public static function dashboard($contactID, &$contentPlacement = self
::DASHBOARD_BELOW
) {
618 $retval = self
::singleton()->invoke(array('contactID', 'contentPlacement'), $contactID, $contentPlacement,
619 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
624 * Note we need this seemingly unnecessary code because in the event that the implementation
625 * of the hook declares the second parameter but doesn't set it, then it comes back unset even
626 * though we have a default value in this function's declaration above.
628 if (!isset($contentPlacement)) {
629 $contentPlacement = self
::DASHBOARD_BELOW
;
636 * This hook is called before storing recently viewed items.
638 * @param array $recentArray
639 * An array of recently viewed or processed items, for in place modification.
643 public static function recent(&$recentArray) {
644 return self
::singleton()->invoke(array('recentArray'), $recentArray,
645 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
651 * Determine how many other records refer to a given record.
653 * @param CRM_Core_DAO $dao
654 * The item for which we want a reference count.
655 * @param array $refCounts
656 * Each item in the array is an Array with keys:
657 * - name: string, eg "sql:civicrm_email:contact_id"
658 * - type: string, eg "sql"
659 * - count: int, eg "5" if there are 5 email addresses that refer to $dao
662 * Return is not really intended to be used.
664 public static function referenceCounts($dao, &$refCounts) {
665 return self
::singleton()->invoke(array('dao', 'refCounts'), $dao, $refCounts,
666 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
667 'civicrm_referenceCounts'
672 * This hook is called when building the amount structure for a Contribution or Event Page.
674 * @param int $pageType
675 * Is this a contribution or event page.
676 * @param CRM_Core_Form $form
677 * Reference to the form object.
678 * @param array $amount
679 * The amount structure to be displayed.
683 public static function buildAmount($pageType, &$form, &$amount) {
684 return self
::singleton()->invoke(array('pageType', 'form', 'amount'), $pageType, $form, $amount, self
::$_nullObject,
685 self
::$_nullObject, self
::$_nullObject, 'civicrm_buildAmount');
689 * This hook is called when building the state list for a particular country.
691 * @param array $countryID
692 * The country id whose states are being selected.
697 public static function buildStateProvinceForCountry($countryID, &$states) {
698 return self
::singleton()->invoke(array('countryID', 'states'), $countryID, $states,
699 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
700 'civicrm_buildStateProvinceForCountry'
705 * This hook is called when rendering the tabs for a contact (q=civicrm/contact/view)c
708 * The array of tabs that will be displayed.
709 * @param int $contactID
710 * The contactID for whom the dashboard is being rendered.
713 * @deprecated Use tabset() instead.
715 public static function tabs(&$tabs, $contactID) {
716 return self
::singleton()->invoke(array('tabs', 'contactID'), $tabs, $contactID,
717 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_tabs'
722 * This hook is called when rendering the tabs used for events and potentially
723 * contribution pages, etc.
725 * @param string $tabsetName
726 * Name of the screen or visual element.
728 * Tabs that will be displayed.
729 * @param array $context
730 * Extra data about the screen or context in which the tab is used.
734 public static function tabset($tabsetName, &$tabs, $context) {
735 return self
::singleton()->invoke(array('tabsetName', 'tabs', 'context'), $tabsetName, $tabs,
736 $context, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_tabset'
741 * This hook is called when sending an email / printing labels
743 * @param array $tokens
744 * The list of tokens that can be used for the contact.
748 public static function tokens(&$tokens) {
749 return self
::singleton()->invoke(array('tokens'), $tokens,
750 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_tokens'
755 * This hook is called when sending an email / printing labels to get the values for all the
756 * tokens returned by the 'tokens' hook
758 * @param array $details
759 * The array to store the token values indexed by contactIDs (unless it a single).
760 * @param array $contactIDs
761 * An array of contactIDs.
763 * The jobID if this is associated with a CiviMail mailing.
764 * @param array $tokens
765 * The list of tokens associated with the content.
766 * @param string $className
767 * The top level className from where the hook is invoked.
771 public static function tokenValues(
778 return self
::singleton()
779 ->invoke(array('details', 'contactIDs', 'jobID', 'tokens', 'className'), $details, $contactIDs, $jobID, $tokens, $className, self
::$_nullObject, 'civicrm_tokenValues');
783 * This hook is called before a CiviCRM Page is rendered. You can use this hook to insert smarty variables
786 * @param object $page
787 * The page that will be rendered.
791 public static function pageRun(&$page) {
792 return self
::singleton()->invoke(array('page'), $page,
793 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
799 * This hook is called after a copy of an object has been made. The current objects are
800 * Event, Contribution Page and UFGroup
802 * @param string $objectName
803 * Name of the object.
804 * @param object $object
805 * Reference to the copy.
809 public static function copy($objectName, &$object) {
810 return self
::singleton()->invoke(array('objectName', 'object'), $objectName, $object,
811 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
817 * This hook is called when a contact unsubscribes from a mailing. It allows modules
818 * to override what the contacts are removed from.
822 * @param int $mailingId
823 * The id of the mailing to unsub from
824 * @param int $contactId
825 * The id of the contact who is unsubscribing
826 * @param array|int $groups
827 * Groups the contact will be removed from.
828 * @param array|int $baseGroups
829 * Base groups (used in smart mailings) the contact will be removed from.
834 public static function unsubscribeGroups($op, $mailingId, $contactId, &$groups, &$baseGroups) {
835 return self
::singleton()
836 ->invoke(array('op', 'mailingId', 'contactId', 'groups', 'baseGroups'), $op, $mailingId, $contactId, $groups, $baseGroups, self
::$_nullObject, 'civicrm_unsubscribeGroups');
840 * This hook is called when CiviCRM needs to edit/display a custom field with options
842 * @deprecated in favor of hook_civicrm_fieldOptions
844 * @param int $customFieldID
845 * The custom field ID.
846 * @param array $options
847 * The current set of options for that custom field.
848 * You can add/remove existing options.
849 * Important: This array may contain meta-data about the field that is needed elsewhere, so it is important
850 * to be careful to not overwrite the array.
851 * Only add/edit/remove the specific field options you intend to affect.
852 * @param bool $detailedFormat
853 * If true, the options are in an ID => array ( 'id' => ID, 'label' => label, 'value' => value ) format
854 * @param array $selectAttributes
855 * Contain select attribute(s) if any.
859 public static function customFieldOptions($customFieldID, &$options, $detailedFormat = FALSE, $selectAttributes = array()) {
860 // Weird: $selectAttributes is inputted but not outputted.
861 return self
::singleton()->invoke(array('customFieldID', 'options', 'detailedFormat'), $customFieldID, $options, $detailedFormat,
862 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
863 'civicrm_customFieldOptions'
868 * Hook for modifying field options
870 * @param string $entity
871 * @param string $field
872 * @param array $options
873 * @param array $params
877 public static function fieldOptions($entity, $field, &$options, $params) {
878 return self
::singleton()->invoke(array('entity', 'field', 'options', 'params'), $entity, $field, $options, $params,
879 self
::$_nullObject, self
::$_nullObject,
880 'civicrm_fieldOptions'
886 * This hook is called to display the list of actions allowed after doing a search.
887 * This allows the module developer to inject additional actions or to remove existing actions.
889 * @param string $objectType
890 * The object type for this search.
891 * - activity, campaign, case, contact, contribution, event, grant, membership, and pledge are supported.
892 * @param array $tasks
893 * The current set of tasks for that custom field.
894 * You can add/remove existing tasks.
895 * Each task needs to have a title (eg 'title' => ts( 'Group - add contacts')) and a class
896 * (eg 'class' => 'CRM_Contact_Form_Task_AddToGroup').
897 * Optional result (boolean) may also be provided. Class can be an array of classes (not sure what that does :( ).
898 * The key for new Task(s) should not conflict with the keys for core tasks of that $objectType, which can be
899 * found in CRM/$objectType/Task.php.
903 public static function searchTasks($objectType, &$tasks) {
904 return self
::singleton()->invoke(array('objectType', 'tasks'), $objectType, $tasks,
905 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
906 'civicrm_searchTasks'
912 * @param array $params
916 public static function eventDiscount(&$form, &$params) {
917 return self
::singleton()->invoke(array('form', 'params'), $form, $params,
918 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
919 'civicrm_eventDiscount'
924 * This hook is called when composing a mailing. You can include / exclude other groups as needed.
927 * The form object for which groups / mailings being displayed
928 * @param array $groups
929 * The list of groups being included / excluded
930 * @param array $mailings
931 * The list of mailings being included / excluded
935 public static function mailingGroups(&$form, &$groups, &$mailings) {
936 return self
::singleton()->invoke(array('form', 'groups', 'mailings'), $form, $groups, $mailings,
937 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
938 'civicrm_mailingGroups'
943 * (Experimental) Modify the list of template-types used for CiviMail composition.
945 * @param array $types
946 * Sequentially indexed list of template types. Each type specifies:
948 * - editorUrl: string, Angular template URL
949 * - weight: int, priority when picking a default value for new mailings
952 public static function mailingTemplateTypes(&$types) {
953 return self
::singleton()->invoke(array('types'), $types, self
::$_nullObject, self
::$_nullObject,
954 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
955 'civicrm_mailingTemplateTypes'
960 * This hook is called when composing the array of membershipTypes and their cost during a membership registration
962 * Note the hook is called on initial page load and also reloaded after submit (PRG pattern).
963 * You can use it to alter the membership types when first loaded, or after submission
964 * (for example if you want to gather data in the form and use it to alter the fees).
967 * The form object that is presenting the page
968 * @param array $membershipTypes
969 * The array of membership types and their amount
973 public static function membershipTypeValues(&$form, &$membershipTypes) {
974 return self
::singleton()->invoke(array('form', 'membershipTypes'), $form, $membershipTypes,
975 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
976 'civicrm_membershipTypeValues'
981 * This hook is called when rendering the contact summary.
983 * @param int $contactID
984 * The contactID for whom the summary is being rendered
985 * @param mixed $content
986 * @param int $contentPlacement
987 * Specifies where the hook content should be displayed relative to the
991 * The html snippet to include in the contact summary
993 public static function summary($contactID, &$content, &$contentPlacement = self
::SUMMARY_BELOW
) {
994 return self
::singleton()->invoke(array('contactID', 'content', 'contentPlacement'), $contactID, $content, $contentPlacement,
995 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1001 * Use this hook to populate the list of contacts returned by Contact Reference custom fields.
1002 * By default, Contact Reference fields will search on and return all CiviCRM contacts.
1003 * If you want to limit the contacts returned to a specific group, or some other criteria
1004 * - you can override that behavior by providing a SQL query that returns some subset of your contacts.
1005 * The hook is called when the query is executed to get the list of contacts to display.
1007 * @param mixed $query
1008 * - the query that will be executed (input and output parameter);.
1009 * It's important to realize that the ACL clause is built prior to this hook being fired,
1010 * so your query will ignore any ACL rules that may be defined.
1011 * Your query must return two columns:
1012 * the contact 'data' to display in the autocomplete dropdown (usually contact.sort_name - aliased as 'data')
1014 * @param string $queryText
1015 * The name string to execute the query against (this is the value being typed in by the user).
1016 * @param string $context
1017 * The context in which this ajax call is being made (for example: 'customfield', 'caseview').
1019 * The id of the object for which the call is being made.
1020 * For custom fields, it will be the custom field id
1024 public static function contactListQuery(&$query, $queryText, $context, $id) {
1025 return self
::singleton()->invoke(array('query', 'queryText', 'context', 'id'), $query, $queryText, $context, $id,
1026 self
::$_nullObject, self
::$_nullObject,
1027 'civicrm_contactListQuery'
1032 * Hook definition for altering payment parameters before talking to a payment processor back end.
1034 * Definition will look like this:
1036 * function hook_civicrm_alterPaymentProcessorParams(
1042 * @param CRM_Core_Payment $paymentObj
1043 * Instance of payment class of the payment processor invoked (e.g., 'CRM_Core_Payment_Dummy')
1044 * See discussion in CRM-16224 as to whether $paymentObj should be passed by reference.
1045 * @param array &$rawParams
1046 * array of params as passed to to the processor
1047 * @param array &$cookedParams
1048 * params after the processor code has translated them into its own key/value pairs
1051 * This return is not really intended to be used.
1053 public static function alterPaymentProcessorParams(
1058 return self
::singleton()->invoke(array('paymentObj', 'rawParams', 'cookedParams'), $paymentObj, $rawParams, $cookedParams,
1059 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1060 'civicrm_alterPaymentProcessorParams'
1065 * This hook is called when an email is about to be sent by CiviCRM.
1067 * @param array $params
1068 * Array fields include: groupName, from, toName, toEmail, subject, cc, bcc, text, html,
1069 * returnPath, replyTo, headers, attachments (array)
1070 * @param string $context
1071 * The context in which the hook is being invoked, eg 'civimail'.
1075 public static function alterMailParams(&$params, $context = NULL) {
1076 return self
::singleton()->invoke(array('params', 'context'), $params, $context,
1077 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1078 'civicrm_alterMailParams'
1083 * This hook is called when membership status is being calculated.
1085 * @param array $membershipStatus
1086 * Membership status details as determined - alter if required.
1087 * @param array $arguments
1088 * Arguments passed in to calculate date.
1093 * - 'exclude_is_admin'
1094 * - 'membership_type_id'
1095 * @param array $membership
1096 * Membership details from the calling function.
1100 public static function alterCalculatedMembershipStatus(&$membershipStatus, $arguments, $membership) {
1101 return self
::singleton()->invoke(array('membershipStatus', 'arguments', 'membership'), $membershipStatus, $arguments,
1102 $membership, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1103 'civicrm_alterCalculatedMembershipStatus'
1108 * This hook is called after getting the content of the mail and before tokenizing it.
1110 * @param array $content
1111 * Array fields include: html, text, subject
1115 public static function alterMailContent(&$content) {
1116 return self
::singleton()->invoke(array('content'), $content,
1117 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1118 'civicrm_alterMailContent'
1123 * This hook is called when rendering the Manage Case screen.
1125 * @param int $caseID
1129 * Array of data to be displayed, where the key is a unique id to be used for styling (div id's)
1130 * and the value is an array with keys 'label' and 'value' specifying label/value pairs
1132 public static function caseSummary($caseID) {
1133 return self
::singleton()->invoke(array('caseID'), $caseID,
1134 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1135 'civicrm_caseSummary'
1140 * This hook is called when locating CiviCase types.
1142 * @param array $caseTypes
1146 public static function caseTypes(&$caseTypes) {
1147 return self
::singleton()
1148 ->invoke(array('caseTypes'), $caseTypes, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_caseTypes');
1152 * This hook is called soon after the CRM_Core_Config object has ben initialized.
1153 * You can use this hook to modify the config object and hence behavior of CiviCRM dynamically.
1155 * @param CRM_Core_Config|array $config
1160 public static function config(&$config) {
1161 return self
::singleton()->invoke(array('config'), $config,
1162 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1168 * This hooks allows to change option values.
1170 * @deprecated in favor of hook_civicrm_fieldOptions
1172 * @param array $options
1173 * Associated array of option values / id
1174 * @param string $groupName
1179 public static function optionValues(&$options, $groupName) {
1180 return self
::singleton()->invoke(array('options', 'groupName'), $options, $groupName,
1181 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1182 'civicrm_optionValues'
1187 * This hook allows modification of the navigation menu.
1189 * @param array $params
1190 * Associated array of navigation menu entry to Modify/Add
1194 public static function navigationMenu(&$params) {
1195 return self
::singleton()->invoke(array('params'), $params,
1196 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1197 'civicrm_navigationMenu'
1202 * This hook allows modification of the data used to perform merging of duplicates.
1204 * @param string $type
1205 * The type of data being passed (cidRefs|eidRefs|relTables|sqls).
1206 * @param array $data
1207 * The data, as described in $type.
1208 * @param int $mainId
1209 * Contact_id of the contact that survives the merge.
1210 * @param int $otherId
1211 * Contact_id of the contact that will be absorbed and deleted.
1212 * @param array $tables
1213 * When $type is "sqls", an array of tables as it may have been handed to the calling function.
1217 public static function merge($type, &$data, $mainId = NULL, $otherId = NULL, $tables = NULL) {
1218 return self
::singleton()->invoke(array('type', 'data', 'mainId', 'otherId', 'tables'), $type, $data, $mainId, $otherId, $tables, self
::$_nullObject, 'civicrm_merge');
1222 * This hook allows modification of the data calculated for merging locations.
1224 * @param array $blocksDAO
1225 * Array of location DAO to be saved. These are arrays in 2 keys 'update' & 'delete'.
1226 * @param int $mainId
1227 * Contact_id of the contact that survives the merge.
1228 * @param int $otherId
1229 * Contact_id of the contact that will be absorbed and deleted.
1230 * @param array $migrationInfo
1231 * Calculated migration info, informational only.
1235 public static function alterLocationMergeData(&$blocksDAO, $mainId, $otherId, $migrationInfo) {
1236 return self
::singleton()->invoke(array('blocksDAO', 'mainId', 'otherId', 'migrationInfo'), $blocksDAO, $mainId, $otherId, $migrationInfo, self
::$_nullObject, self
::$_nullObject, 'civicrm_alterLocationMergeData');
1240 * This hook provides a way to override the default privacy behavior for notes.
1242 * @param array &$noteValues
1243 * Associative array of values for this note
1247 public static function notePrivacy(&$noteValues) {
1248 return self
::singleton()->invoke(array('noteValues'), $noteValues,
1249 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1250 'civicrm_notePrivacy'
1255 * This hook is called before record is exported as CSV.
1257 * @param string $exportTempTable
1258 * Name of the temporary export table used during export.
1259 * @param array $headerRows
1260 * Header rows for output.
1261 * @param array $sqlColumns
1263 * @param int $exportMode
1264 * Export mode ( contact, contribution, etc...).
1268 public static function export(&$exportTempTable, &$headerRows, &$sqlColumns, &$exportMode) {
1269 return self
::singleton()->invoke(array('exportTempTable', 'headerRows', 'sqlColumns', 'exportMode'), $exportTempTable, $headerRows, $sqlColumns, $exportMode,
1270 self
::$_nullObject, self
::$_nullObject,
1276 * This hook allows modification of the queries constructed from dupe rules.
1278 * @param string $obj
1279 * Object of rulegroup class.
1280 * @param string $type
1281 * Type of queries e.g table / threshold.
1282 * @param array $query
1287 public static function dupeQuery($obj, $type, &$query) {
1288 return self
::singleton()->invoke(array('obj', 'type', 'query'), $obj, $type, $query,
1289 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1295 * This hook is called AFTER EACH email has been processed by the script bin/EmailProcessor.php
1297 * @param string $type
1298 * Type of mail processed: 'activity' OR 'mailing'.
1299 * @param array &$params the params that were sent to the CiviCRM API function
1300 * @param object $mail
1301 * The mail object which is an ezcMail class.
1302 * @param array &$result the result returned by the api call
1303 * @param string $action
1304 * (optional ) the requested action to be performed if the types was 'mailing'.
1308 public static function emailProcessor($type, &$params, $mail, &$result, $action = NULL) {
1309 return self
::singleton()
1310 ->invoke(array('type', 'params', 'mail', 'result', 'action'), $type, $params, $mail, $result, $action, self
::$_nullObject, 'civicrm_emailProcessor');
1314 * This hook is called after a row has been processed and the
1315 * record (and associated records imported
1317 * @param string $object
1318 * Object being imported (for now Contact only, later Contribution, Activity,.
1319 * Participant and Member)
1320 * @param string $usage
1321 * Hook usage/location (for now process only, later mapping and others).
1322 * @param string $objectRef
1323 * Import record object.
1324 * @param array $params
1325 * Array with various key values: currently.
1326 * contactID - contact id
1327 * importID - row id in temp table
1328 * importTempTable - name of tempTable
1329 * fieldHeaders - field headers
1330 * fields - import fields
1334 public static function import($object, $usage, &$objectRef, &$params) {
1335 return self
::singleton()->invoke(array('object', 'usage', 'objectRef', 'params'), $object, $usage, $objectRef, $params,
1336 self
::$_nullObject, self
::$_nullObject,
1342 * This hook is called when API permissions are checked (cf. civicrm_api3_api_check_permission()
1343 * in api/v3/utils.php and _civicrm_api3_permissions() in CRM/Core/DAO/permissions.php).
1345 * @param string $entity
1346 * The API entity (like contact).
1347 * @param string $action
1348 * The API action (like get).
1349 * @param array &$params the API parameters
1350 * @param array &$permissions the associative permissions array (probably to be altered by this hook)
1354 public static function alterAPIPermissions($entity, $action, &$params, &$permissions) {
1355 return self
::singleton()->invoke(array('entity', 'action', 'params', 'permissions'), $entity, $action, $params, $permissions,
1356 self
::$_nullObject, self
::$_nullObject,
1357 'civicrm_alterAPIPermissions'
1362 * @param CRM_Core_DAO $dao
1366 public static function postSave(&$dao) {
1367 $hookName = 'civicrm_postSave_' . $dao->getTableName();
1368 return self
::singleton()->invoke(array('dao'), $dao,
1369 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1375 * This hook allows user to customize context menu Actions on contact summary page.
1377 * @param array $actions
1378 * Array of all Actions in contextmenu.
1379 * @param int $contactID
1380 * ContactID for the summary page.
1384 public static function summaryActions(&$actions, $contactID = NULL) {
1385 return self
::singleton()->invoke(array('actions', 'contactID'), $actions, $contactID,
1386 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1387 'civicrm_summaryActions'
1392 * This hook is called from CRM_Core_Selector_Controller through which all searches in civicrm go.
1393 * This enables us hook implementors to modify both the headers and the rows
1395 * The BIGGEST drawback with this hook is that you may need to modify the result template to include your
1396 * fields. The result files are CRM/{Contact,Contribute,Member,Event...}/Form/Selector.tpl
1398 * However, if you use the same number of columns, you can overwrite the existing columns with the values that
1399 * you want displayed. This is a hackish, but avoids template modification.
1401 * @param string $objectName
1402 * The component name that we are doing the search.
1403 * activity, campaign, case, contact, contribution, event, grant, membership, and pledge
1404 * @param array &$headers the list of column headers, an associative array with keys: ( name, sort, order )
1405 * @param array &$rows the list of values, an associate array with fields that are displayed for that component
1406 * @param array $selector
1407 * the selector object. Allows you access to the context of the search
1410 * modify the header and values object to pass the data you need
1412 public static function searchColumns($objectName, &$headers, &$rows, &$selector) {
1413 return self
::singleton()->invoke(array('objectName', 'headers', 'rows', 'selector'), $objectName, $headers, $rows, $selector,
1414 self
::$_nullObject, self
::$_nullObject,
1415 'civicrm_searchColumns'
1420 * This hook is called when uf groups are being built for a module.
1422 * @param string $moduleName
1424 * @param array $ufGroups
1425 * Array of ufgroups for a module.
1429 public static function buildUFGroupsForModule($moduleName, &$ufGroups) {
1430 return self
::singleton()->invoke(array('moduleName', 'ufGroups'), $moduleName, $ufGroups,
1431 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1432 'civicrm_buildUFGroupsForModule'
1437 * This hook is called when we are determining the contactID for a specific
1440 * @param string $email
1441 * The email address.
1442 * @param int $contactID
1443 * The contactID that matches this email address, IF it exists.
1444 * @param array $result
1445 * (reference) has two fields.
1446 * contactID - the new (or same) contactID
1447 * action - 3 possible values:
1448 * CRM_Utils_Mail_Incoming::EMAILPROCESSOR_CREATE_INDIVIDUAL - create a new contact record
1449 * CRM_Utils_Mail_Incoming::EMAILPROCESSOR_OVERRIDE - use the new contactID
1450 * CRM_Utils_Mail_Incoming::EMAILPROCESSOR_IGNORE - skip this email address
1454 public static function emailProcessorContact($email, $contactID, &$result) {
1455 return self
::singleton()->invoke(array('email', 'contactID', 'result'), $email, $contactID, $result,
1456 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1457 'civicrm_emailProcessorContact'
1462 * Hook definition for altering the generation of Mailing Labels.
1464 * @param array $args
1465 * An array of the args in the order defined for the tcpdf multiCell api call.
1466 * with the variable names below converted into string keys (ie $w become 'w'
1467 * as the first key for $args)
1468 * float $w Width of cells. If 0, they extend up to the right margin of the page.
1469 * float $h Cell minimum height. The cell extends automatically if needed.
1470 * string $txt String to print
1471 * mixed $border Indicates if borders must be drawn around the cell block. The value can
1472 * be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or
1473 * a string containing some or all of the following characters (in any order):
1474 * <ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul>
1475 * string $align Allows to center or align the text. Possible values are:<ul><li>L or empty string:
1476 * left align</li><li>C: center</li><li>R: right align</li><li>J: justification
1477 * (default value when $ishtml=false)</li></ul>
1478 * int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
1479 * int $ln Indicates where the current position should go after the call. Possible values are:<ul><li>0:
1480 * to the right</li><li>1: to the beginning of the next line [DEFAULT]</li><li>2: below</li></ul>
1481 * float $x x position in user units
1482 * float $y y position in user units
1483 * boolean $reseth if true reset the last cell height (default true).
1484 * int $stretch stretch character mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if
1485 * necessary</li><li>2 = forced horizontal scaling</li><li>3 = character spacing only if
1486 * necessary</li><li>4 = forced character spacing</li></ul>
1487 * boolean $ishtml set to true if $txt is HTML content (default = false).
1488 * boolean $autopadding if true, uses internal padding and automatically adjust it to account for line width.
1489 * float $maxh maximum height. It should be >= $h and less then remaining space to the bottom of the page,
1490 * or 0 for disable this feature. This feature works only when $ishtml=false.
1494 public static function alterMailingLabelParams(&$args) {
1495 return self
::singleton()->invoke(array('args'), $args,
1496 self
::$_nullObject, self
::$_nullObject,
1497 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1498 'civicrm_alterMailingLabelParams'
1503 * This hooks allows alteration of generated page content.
1506 * Previously generated content.
1508 * Context of content - page or form.
1510 * The file name of the tpl.
1512 * A reference to the page or form object.
1516 public static function alterContent(&$content, $context, $tplName, &$object) {
1517 return self
::singleton()->invoke(array('content', 'context', 'tplName', 'object'), $content, $context, $tplName, $object,
1518 self
::$_nullObject, self
::$_nullObject,
1519 'civicrm_alterContent'
1524 * This hooks allows alteration of the tpl file used to generate content. It differs from the
1525 * altercontent hook as the content has already been rendered through the tpl at that point
1528 * Previously generated content.
1530 * Reference to the form object.
1532 * Context of content - page or form.
1534 * Reference the file name of the tpl.
1538 public static function alterTemplateFile($formName, &$form, $context, &$tplName) {
1539 return self
::singleton()->invoke(array('formName', 'form', 'context', 'tplName'), $formName, $form, $context, $tplName,
1540 self
::$_nullObject, self
::$_nullObject,
1541 'civicrm_alterTemplateFile'
1546 * This hook collects the trigger definition from all components.
1549 * @param string $tableName
1550 * (optional) the name of the table that we are interested in only.
1552 * @internal param \reference $triggerInfo to an array of trigger information
1553 * each element has 4 fields:
1554 * table - array of tableName
1555 * when - BEFORE or AFTER
1556 * event - array of eventName - INSERT OR UPDATE OR DELETE
1557 * sql - array of statements optionally terminated with a ;
1558 * a statement can use the tokes {tableName} and {eventName}
1559 * to do token replacement with the table / event. This allows
1560 * templatizing logging and other hooks
1563 public static function triggerInfo(&$info, $tableName = NULL) {
1564 return self
::singleton()->invoke(array('info', 'tableName'), $info, $tableName,
1565 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1567 'civicrm_triggerInfo'
1571 * This hook allows changes to the spec of which tables to log.
1573 * @param array $logTableSpec
1577 public static function alterLogTables(&$logTableSpec) {
1578 return self
::singleton()->invoke(array('logTableSpec'), $logTableSpec, $_nullObject,
1579 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1581 'civicrm_alterLogTables'
1586 * This hook is called when a module-extension is installed.
1587 * Each module will receive hook_civicrm_install during its own installation (but not during the
1588 * installation of unrelated modules).
1590 public static function install() {
1591 return self
::singleton()->invoke(0, self
::$_nullObject,
1592 self
::$_nullObject, self
::$_nullObject,
1593 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1599 * This hook is called when a module-extension is uninstalled.
1600 * Each module will receive hook_civicrm_uninstall during its own uninstallation (but not during the
1601 * uninstallation of unrelated modules).
1603 public static function uninstall() {
1604 return self
::singleton()->invoke(0, self
::$_nullObject,
1605 self
::$_nullObject, self
::$_nullObject,
1606 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1612 * This hook is called when a module-extension is re-enabled.
1613 * Each module will receive hook_civicrm_enable during its own re-enablement (but not during the
1614 * re-enablement of unrelated modules).
1616 public static function enable() {
1617 return self
::singleton()->invoke(0, self
::$_nullObject,
1618 self
::$_nullObject, self
::$_nullObject,
1619 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1625 * This hook is called when a module-extension is disabled.
1626 * Each module will receive hook_civicrm_disable during its own disablement (but not during the
1627 * disablement of unrelated modules).
1629 public static function disable() {
1630 return self
::singleton()->invoke(0, self
::$_nullObject,
1631 self
::$_nullObject, self
::$_nullObject,
1632 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1644 public static function alterReportVar($varType, &$var, &$object) {
1645 return self
::singleton()->invoke(array('varType', 'var', 'object'), $varType, $var, $object,
1647 self
::$_nullObject, self
::$_nullObject,
1648 'civicrm_alterReportVar'
1653 * This hook is called to drive database upgrades for extension-modules.
1656 * The type of operation being performed; 'check' or 'enqueue'.
1657 * @param CRM_Queue_Queue $queue
1658 * (for 'enqueue') the modifiable list of pending up upgrade tasks.
1661 * NULL, if $op is 'enqueue'.
1662 * TRUE, if $op is 'check' and upgrades are pending.
1663 * FALSE, if $op is 'check' and upgrades are not pending.
1665 public static function upgrade($op, CRM_Queue_Queue
$queue = NULL) {
1666 return self
::singleton()->invoke(array('op', 'queue'), $op, $queue,
1667 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1674 * This hook is called when an email has been successfully sent by CiviCRM, but not on an error.
1676 * @param array $params
1677 * The mailing parameters. Array fields include: groupName, from, toName,
1678 * toEmail, subject, cc, bcc, text, html, returnPath, replyTo, headers,
1679 * attachments (array)
1683 public static function postEmailSend(&$params) {
1684 return self
::singleton()->invoke(array('params'), $params,
1685 self
::$_nullObject, self
::$_nullObject,
1686 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1687 'civicrm_postEmailSend'
1692 * This hook is called when a CiviMail mailing has completed
1694 * @param int $mailingId
1699 public static function postMailing($mailingId) {
1700 return self
::singleton()->invoke(array('mailingId'), $mailingId,
1701 self
::$_nullObject, self
::$_nullObject,
1702 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1703 'civicrm_postMailing'
1708 * This hook is called when Settings specifications are loaded.
1710 * @param array $settingsFolders
1711 * List of paths from which to derive metadata
1715 public static function alterSettingsFolders(&$settingsFolders) {
1716 return self
::singleton()->invoke(array('settingsFolders'), $settingsFolders,
1717 self
::$_nullObject, self
::$_nullObject,
1718 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1719 'civicrm_alterSettingsFolders'
1724 * This hook is called when Settings have been loaded from the xml
1725 * It is an opportunity for hooks to alter the data
1727 * @param array $settingsMetaData
1728 * Settings Metadata.
1729 * @param int $domainID
1730 * @param mixed $profile
1734 public static function alterSettingsMetaData(&$settingsMetaData, $domainID, $profile) {
1735 return self
::singleton()->invoke(array('settingsMetaData', 'domainID', 'profile'), $settingsMetaData,
1736 $domainID, $profile,
1737 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1738 'civicrm_alterSettingsMetaData'
1743 * This hook is called before running an api call.
1745 * @param API_Wrapper[] $wrappers
1746 * (see CRM_Utils_API_ReloadOption as an example)
1747 * @param mixed $apiRequest
1750 * The return value is ignored
1752 public static function apiWrappers(&$wrappers, $apiRequest) {
1753 return self
::singleton()
1754 ->invoke(array('wrappers', 'apiRequest'), $wrappers, $apiRequest, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1755 self
::$_nullObject, 'civicrm_apiWrappers'
1760 * This hook is called before running pending cron jobs.
1762 * @param CRM_Core_JobManager $jobManager
1765 * The return value is ignored.
1767 public static function cron($jobManager) {
1768 return self
::singleton()->invoke(array('jobManager'),
1769 $jobManager, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1775 * This hook is called when loading CMS permissions; use this hook to modify
1776 * the array of system permissions for CiviCRM.
1778 * @param array $permissions
1779 * Array of permissions. See CRM_Core_Permission::getCorePermissions() for
1780 * the format of this array.
1783 * The return value is ignored
1785 public static function permission(&$permissions) {
1786 return self
::singleton()->invoke(array('permissions'), $permissions,
1787 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1788 'civicrm_permission'
1793 * This hook is called when checking permissions; use this hook to dynamically
1794 * escalate user permissions in certain use cases (cf. CRM-19256).
1796 * @param string $permission
1797 * The name of an atomic permission, ie. 'access deleted contacts'
1798 * @param bool $granted
1799 * Whether this permission is currently granted. The hook can change this value.
1802 * The return value is ignored
1804 public static function permission_check($permission, &$granted) {
1805 return self
::singleton()->invoke(array('permission', 'granted'), $permission, $granted,
1806 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1807 'civicrm_permission_check'
1812 * @param CRM_Core_Exception Exception $exception
1813 * @param mixed $request
1814 * Reserved for future use.
1816 public static function unhandledException($exception, $request = NULL) {
1817 $event = new \Civi\Core\Event\
UnhandledExceptionEvent($exception, self
::$_nullObject);
1818 \Civi
::dispatcher()->dispatch('hook_civicrm_unhandled_exception', $event);
1822 * This hook is called for declaring managed entities via API.
1824 * Note: This is a preboot hook. It will dispatch via the extension/module
1825 * subsystem but *not* the Symfony EventDispatcher.
1827 * @param array[] $entityTypes
1828 * List of entity types; each entity-type is an array with keys:
1829 * - name: string, a unique short name (e.g. "ReportInstance")
1830 * - class: string, a PHP DAO class (e.g. "CRM_Report_DAO_Instance")
1831 * - table: string, a SQL table name (e.g. "civicrm_report_instance")
1832 * - fields_callback: array, list of callables which manipulates field list
1833 * - links_callback: array, list of callables which manipulates fk list
1836 * The return value is ignored
1838 public static function entityTypes(&$entityTypes) {
1839 return self
::singleton()->invoke(array('entityTypes'), $entityTypes, self
::$_nullObject, self
::$_nullObject,
1840 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_entityTypes'
1845 * Build a description of available hooks.
1847 * @param \Civi\Core\CiviEventInspector $inspector
1849 public static function eventDefs($inspector) {
1850 $event = \Civi\Core\Event\GenericHookEvent
::create(array(
1851 'inspector' => $inspector,
1853 Civi
::dispatcher()->dispatch('hook_civicrm_eventDefs', $event);
1857 * This hook is called while preparing a profile form.
1859 * @param string $profileName
1862 public static function buildProfile($profileName) {
1863 return self
::singleton()->invoke(array('profileName'), $profileName, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1864 self
::$_nullObject, self
::$_nullObject, 'civicrm_buildProfile');
1868 * This hook is called while validating a profile form submission.
1870 * @param string $profileName
1873 public static function validateProfile($profileName) {
1874 return self
::singleton()->invoke(array('profileName'), $profileName, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1875 self
::$_nullObject, self
::$_nullObject, 'civicrm_validateProfile');
1879 * This hook is called processing a valid profile form submission.
1881 * @param string $profileName
1884 public static function processProfile($profileName) {
1885 return self
::singleton()->invoke(array('profileName'), $profileName, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1886 self
::$_nullObject, self
::$_nullObject, 'civicrm_processProfile');
1890 * This hook is called while preparing a read-only profile screen
1892 * @param string $profileName
1895 public static function viewProfile($profileName) {
1896 return self
::singleton()->invoke(array('profileName'), $profileName, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1897 self
::$_nullObject, self
::$_nullObject, 'civicrm_viewProfile');
1901 * This hook is called while preparing a list of contacts (based on a profile)
1903 * @param string $profileName
1906 public static function searchProfile($profileName) {
1907 return self
::singleton()->invoke(array('profileName'), $profileName, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1908 self
::$_nullObject, self
::$_nullObject, 'civicrm_searchProfile');
1912 * This hook is invoked when building a CiviCRM name badge.
1914 * @param string $labelName
1915 * String referencing name of badge format.
1916 * @param object $label
1917 * Reference to the label object.
1918 * @param array $format
1919 * Array of format data.
1920 * @param array $participant
1921 * Array of participant values.
1924 * the return value is ignored
1926 public static function alterBadge($labelName, &$label, &$format, &$participant) {
1927 return self
::singleton()
1928 ->invoke(array('labelName', 'label', 'format', 'participant'), $labelName, $label, $format, $participant, self
::$_nullObject, self
::$_nullObject, 'civicrm_alterBadge');
1933 * This hook is called before encoding data in barcode.
1935 * @param array $data
1936 * Associated array of values available for encoding.
1937 * @param string $type
1938 * Type of barcode, classic barcode or QRcode.
1939 * @param string $context
1940 * Where this hooks is invoked.
1944 public static function alterBarcode(&$data, $type = 'barcode', $context = 'name_badge') {
1945 return self
::singleton()->invoke(array('data', 'type', 'context'), $data, $type, $context, self
::$_nullObject,
1946 self
::$_nullObject, self
::$_nullObject, 'civicrm_alterBarcode');
1950 * Modify or replace the Mailer object used for outgoing mail.
1952 * @param object $mailer
1953 * The default mailer produced by normal configuration; a PEAR "Mail" class (like those returned by Mail::factory)
1954 * @param string $driver
1955 * The type of the default mailer (eg "smtp", "sendmail", "mock", "CRM_Mailing_BAO_Spool")
1956 * @param array $params
1957 * The default mailer config options
1960 * @see Mail::factory
1962 public static function alterMailer(&$mailer, $driver, $params) {
1963 return self
::singleton()
1964 ->invoke(array('mailer', 'driver', 'params'), $mailer, $driver, $params, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_alterMailer');
1968 * Deprecated: Misnamed version of alterMailer(). Remove post-4.7.x.
1969 * Modify or replace the Mailer object used for outgoing mail.
1971 * @param object $mailer
1972 * The default mailer produced by normal configuration; a PEAR "Mail" class (like those returned by Mail::factory)
1973 * @param string $driver
1974 * The type of the default mailer (eg "smtp", "sendmail", "mock", "CRM_Mailing_BAO_Spool")
1975 * @param array $params
1976 * The default mailer config options
1979 * @see Mail::factory
1982 public static function alterMail(&$mailer, $driver, $params) {
1983 return CRM_Utils_Hook
::alterMailer($mailer, $driver, $params);
1987 * This hook is called while building the core search query,
1988 * so hook implementers can provide their own query objects which alters/extends core search.
1990 * @param array $queryObjects
1991 * @param string $type
1995 public static function queryObjects(&$queryObjects, $type = 'Contact') {
1996 return self
::singleton()
1997 ->invoke(array('queryObjects', 'type'), $queryObjects, $type, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_queryObjects');
2001 * This hook is called while viewing contact dashboard.
2003 * @param array $availableDashlets
2004 * List of dashlets; each is formatted per api/v3/Dashboard
2005 * @param array $defaultDashlets
2006 * List of dashlets; each is formatted per api/v3/DashboardContact
2010 public static function dashboard_defaults($availableDashlets, &$defaultDashlets) {
2011 return self
::singleton()
2012 ->invoke(array('availableDashlets', 'defaultDashlets'), $availableDashlets, $defaultDashlets, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_dashboard_defaults');
2016 * This hook is called before a case merge (or a case reassign)
2018 * @param int $mainContactId
2019 * @param int $mainCaseId
2020 * @param int $otherContactId
2021 * @param int $otherCaseId
2022 * @param bool $changeClient
2026 public static function pre_case_merge($mainContactId, $mainCaseId = NULL, $otherContactId = NULL, $otherCaseId = NULL, $changeClient = FALSE) {
2027 return self
::singleton()
2028 ->invoke(array('mainContactId', 'mainCaseId', 'otherContactId', 'otherCaseId', 'changeClient'), $mainContactId, $mainCaseId, $otherContactId, $otherCaseId, $changeClient, self
::$_nullObject, 'civicrm_pre_case_merge');
2032 * This hook is called after a case merge (or a case reassign)
2034 * @param int $mainContactId
2035 * @param int $mainCaseId
2036 * @param int $otherContactId
2037 * @param int $otherCaseId
2038 * @param bool $changeClient
2042 public static function post_case_merge($mainContactId, $mainCaseId = NULL, $otherContactId = NULL, $otherCaseId = NULL, $changeClient = FALSE) {
2043 return self
::singleton()
2044 ->invoke(array('mainContactId', 'mainCaseId', 'otherContactId', 'otherCaseId', 'changeClient'), $mainContactId, $mainCaseId, $otherContactId, $otherCaseId, $changeClient, self
::$_nullObject, 'civicrm_post_case_merge');
2049 * Add a hook for altering the display name
2051 * hook_civicrm_contact_get_displayname(&$display_name, $objContact)
2053 * @param string $displayName
2054 * @param int $contactId
2055 * @param object $dao
2056 * The contact object.
2060 public static function alterDisplayName(&$displayName, $contactId, $dao) {
2061 return self
::singleton()->invoke(array('displayName', 'contactId', 'dao'),
2062 $displayName, $contactId, $dao, self
::$_nullObject, self
::$_nullObject,
2063 self
::$_nullObject, 'civicrm_contact_get_displayname'
2068 * EXPERIMENTAL: This hook allows one to register additional Angular modules
2070 * @param array $angularModules
2073 * the return value is ignored
2076 * function mymod_civicrm_angularModules(&$angularModules) {
2077 * $angularModules['myAngularModule'] = array(
2078 * 'ext' => 'org.example.mymod',
2079 * 'js' => array('js/myAngularModule.js'),
2081 * $angularModules['myBigAngularModule'] = array(
2082 * 'ext' => 'org.example.mymod',
2083 * 'js' => array('js/part1.js', 'js/part2.js'),
2084 * 'css' => array('css/myAngularModule.css'),
2085 * 'partials' => array('partials/myBigAngularModule'),
2090 public static function angularModules(&$angularModules) {
2091 return self
::singleton()->invoke(array('angularModules'), $angularModules,
2092 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
2093 'civicrm_angularModules'
2098 * This hook fires whenever a record in a case changes.
2100 * @param \Civi\CCase\Analyzer $analyzer
2101 * A bundle of data about the case (such as the case and activity records).
2103 public static function caseChange(\Civi\CCase\Analyzer
$analyzer) {
2104 $event = new \Civi\CCase\Event\
CaseChangeEvent($analyzer);
2105 \Civi
::dispatcher()->dispatch('hook_civicrm_caseChange', $event);
2109 * Generate a default CRUD URL for an entity.
2111 * @param array $spec
2113 * - action: int, eg CRM_Core_Action::VIEW or CRM_Core_Action::UPDATE
2114 * - entity_table: string
2116 * @param CRM_Core_DAO $bao
2117 * @param array $link
2118 * To define the link, add these keys to $link:.
2122 * - url: string (used in lieu of "path"/"query")
2123 * Note: if making "url" CRM_Utils_System::url(), set $htmlize=false
2126 public static function crudLink($spec, $bao, &$link) {
2127 return self
::singleton()->invoke(array('spec', 'bao', 'link'), $spec, $bao, $link,
2128 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
2134 * Modify the CiviCRM container - add new services, parameters, extensions, etc.
2137 * use Symfony\Component\Config\Resource\FileResource;
2138 * use Symfony\Component\DependencyInjection\Definition;
2140 * function mymodule_civicrm_container($container) {
2141 * $container->addResource(new FileResource(__FILE__));
2142 * $container->setDefinition('mysvc', new Definition('My\Class', array()));
2146 * Tip: The container configuration will be compiled/cached. The default cache
2147 * behavior is aggressive. When you first implement the hook, be sure to
2148 * flush the cache. Additionally, you should relax caching during development.
2149 * In `civicrm.settings.php`, set define('CIVICRM_CONTAINER_CACHE', 'auto').
2151 * Note: This is a preboot hook. It will dispatch via the extension/module
2152 * subsystem but *not* the Symfony EventDispatcher.
2154 * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
2155 * @see http://symfony.com/doc/current/components/dependency_injection/index.html
2157 public static function container(\Symfony\Component\DependencyInjection\ContainerBuilder
$container) {
2158 self
::singleton()->invoke(array('container'), $container, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_container');
2162 * @param array <CRM_Core_FileSearchInterface> $fileSearches
2165 public static function fileSearches(&$fileSearches) {
2166 return self
::singleton()->invoke(array('fileSearches'), $fileSearches,
2167 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
2168 'civicrm_fileSearches'
2173 * Check system status.
2175 * @param array $messages
2176 * Array<CRM_Utils_Check_Message>. A list of messages regarding system status.
2179 public static function check(&$messages) {
2180 return self
::singleton()
2181 ->invoke(array('messages'), $messages, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_check');
2185 * This hook is called when a query string of the CSV Batch export is generated.
2187 * @param string $query
2191 public static function batchQuery(&$query) {
2192 return self
::singleton()->invoke(array('query'), $query, self
::$_nullObject,
2193 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
2194 'civicrm_batchQuery'
2199 * This hook is called to alter Deferred revenue item values just before they are
2200 * inserted in civicrm_financial_trxn table
2202 * @param array $deferredRevenues
2204 * @param array $contributionDetails
2206 * @param bool $update
2208 * @param string $context
2212 public static function alterDeferredRevenueItems(&$deferredRevenues, $contributionDetails, $update, $context) {
2213 return self
::singleton()->invoke(array('deferredRevenues', 'contributionDetails', 'update', 'context'), $deferredRevenues, $contributionDetails, $update, $context,
2214 self
::$_nullObject, self
::$_nullObject, 'civicrm_alterDeferredRevenueItems'
2219 * This hook is called when the entries of the CSV Batch export are mapped.
2221 * @param array $results
2222 * @param array $items
2226 public static function batchItems(&$results, &$items) {
2227 return self
::singleton()->invoke(array('results', 'items'), $results, $items,
2228 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
2229 'civicrm_batchItems'
2234 * This hook is called when core resources are being loaded
2236 * @see CRM_Core_Resources::coreResourceList
2238 * @param array $list
2239 * @param string $region
2241 public static function coreResourceList(&$list, $region) {
2242 // First allow the cms integration to add to the list
2243 CRM_Core_Config
::singleton()->userSystem
->appendCoreResources($list);
2245 self
::singleton()->invoke(array('list', 'region'), $list, $region,
2246 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
2247 'civicrm_coreResourceList'
2252 * Allows the list of filters on the EntityRef widget to be altered.
2254 * @see CRM_Core_Resources::entityRefFilters
2256 * @param array $filters
2258 public static function entityRefFilters(&$filters) {
2259 self
::singleton()->invoke(array('filters'), $filters, self
::$_nullObject, self
::$_nullObject,
2260 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
2261 'civicrm_entityRefFilters'
2266 * This hook is called for bypass a few civicrm urls from IDS check.
2268 * @param array $skip list of civicrm urls
2272 public static function idsException(&$skip) {
2273 return self
::singleton()->invoke(array('skip'), $skip, self
::$_nullObject,
2274 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
2275 'civicrm_idsException'
2280 * This hook is called when a geocoder's format method is called.
2282 * @param string $geoProvider
2283 * @param array $values
2284 * @param SimpleXMLElement $xml
2288 public static function geocoderFormat($geoProvider, &$values, $xml) {
2289 return self
::singleton()->invoke(array('geoProvider', 'values', 'xml'), $geoProvider, $values, $xml,
2290 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
2291 'civicrm_geocoderFormat'