3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
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;
92 public function __construct() {
93 $this->cache
= CRM_Utils_Cache
::create(array(
95 'type' => array('ArrayCache'),
103 * @param int $numParams
104 * Number of parameters to pass to the hook.
106 * Parameter to be passed to the hook.
108 * Parameter to be passed 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.
117 * @param string $fnSuffix
118 * Function suffix, this is effectively the hook name.
122 public abstract function invoke(
124 &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6,
129 * @param array $numParams
141 public function commonInvoke(
143 &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6,
147 $this->commonBuildModuleList($fnPrefix);
149 return $this->runHooks($this->commonCiviModules
, $fnSuffix,
150 $numParams, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6
155 * Build the list of modules to be processed for hooks.
157 * @param string $fnPrefix
159 public function commonBuildModuleList($fnPrefix) {
160 if (!$this->commonIncluded
) {
161 // include external file
162 $this->commonIncluded
= TRUE;
164 $config = CRM_Core_Config
::singleton();
165 if (!empty($config->customPHPPathDir
) &&
166 file_exists("{$config->customPHPPathDir}/civicrmHooks.php")
168 @include_once
"civicrmHooks.php";
171 if (!empty($fnPrefix)) {
172 $this->commonCiviModules
[$fnPrefix] = $fnPrefix;
175 $this->requireCiviModules($this->commonCiviModules
);
180 * @param $civiModules
182 * @param array $numParams
192 public function runHooks(
193 $civiModules, $fnSuffix, $numParams,
194 &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6
196 // $civiModules is *not* passed by reference because runHooks
197 // must be reentrant. PHP is finicky about running
198 // multiple loops over the same variable. The circumstances
199 // to reproduce the issue are pretty intricate.
202 $fnNames = $this->cache
->get($fnSuffix);
203 if (!is_array($fnNames)) {
205 if ($civiModules !== NULL) {
206 foreach ($civiModules as $module) {
207 $fnName = "{$module}_{$fnSuffix}";
208 if (function_exists($fnName)) {
209 $fnNames[] = $fnName;
212 $this->cache
->set($fnSuffix, $fnNames);
216 foreach ($fnNames as $fnName) {
218 switch ($numParams) {
220 $fResult = $fnName();
224 $fResult = $fnName($arg1);
228 $fResult = $fnName($arg1, $arg2);
232 $fResult = $fnName($arg1, $arg2, $arg3);
236 $fResult = $fnName($arg1, $arg2, $arg3, $arg4);
240 $fResult = $fnName($arg1, $arg2, $arg3, $arg4, $arg5);
244 $fResult = $fnName($arg1, $arg2, $arg3, $arg4, $arg5, $arg6);
248 CRM_Core_Error
::fatal(ts('Invalid hook invocation'));
252 if (!empty($fResult) &&
255 $result = array_merge($result, $fResult);
259 return empty($result) ?
TRUE : $result;
265 public function requireCiviModules(&$moduleList) {
266 $civiModules = CRM_Core_PseudoConstant
::getModuleExtensions();
267 foreach ($civiModules as $civiModule) {
268 if (!file_exists($civiModule['filePath'])) {
269 CRM_Core_Session
::setStatus(
270 ts('Error loading module file (%1). Please restore the file or disable the module.',
271 array(1 => $civiModule['filePath'])),
272 ts('Warning'), 'error');
275 include_once $civiModule['filePath'];
276 $moduleList[$civiModule['prefix']] = $civiModule['prefix'];
281 * This hook is called before a db write on some core objects.
282 * This hook does not allow the abort of the operation
285 * The type of operation being performed.
286 * @param string $objectName
287 * The name of the object.
289 * The object id if available.
290 * @param array $params
291 * The parameters used for object creation / editing.
294 * the return value is ignored
296 public static function pre($op, $objectName, $id, &$params) {
297 $event = new \Civi\Core\Event\
PreEvent($op, $objectName, $id, $params);
298 \Civi
::service('dispatcher')->dispatch("hook_civicrm_pre", $event);
299 \Civi
::service('dispatcher')->dispatch("hook_civicrm_pre::$objectName", $event);
300 return self
::singleton()
301 ->invoke(4, $op, $objectName, $id, $params, self
::$_nullObject, self
::$_nullObject, 'civicrm_pre');
305 * This hook is called after a db write on some core objects.
308 * The type of operation being performed.
309 * @param string $objectName
310 * The name of the object.
311 * @param int $objectId
312 * The unique identifier for the object.
313 * @param object $objectRef
314 * The reference to the object if available.
317 * based on op. pre-hooks return a boolean or
318 * an error message which aborts the operation
320 public static function post($op, $objectName, $objectId, &$objectRef) {
321 $event = new \Civi\Core\Event\
PostEvent($op, $objectName, $objectId, $objectRef);
322 \Civi
::service('dispatcher')->dispatch("hook_civicrm_post", $event);
323 \Civi
::service('dispatcher')->dispatch("hook_civicrm_post::$objectName", $event);
324 return self
::singleton()
325 ->invoke(4, $op, $objectName, $objectId, $objectRef, self
::$_nullObject, self
::$_nullObject, 'civicrm_post');
329 * This hook retrieves links from other modules and injects it into.
330 * the view contact tabs
333 * The type of operation being performed.
334 * @param string $objectName
335 * The name of the object.
336 * @param int $objectId
337 * The unique identifier for the object.
338 * @param array $links
339 * (optional) the links array (introduced in v3.2).
341 * (optional) the bitmask to show/hide links.
342 * @param array $values
343 * (optional) the values to fill the links.
346 * the return value is ignored
348 public static function links($op, $objectName, &$objectId, &$links, &$mask = NULL, &$values = array()) {
349 return self
::singleton()->invoke(6, $op, $objectName, $objectId, $links, $mask, $values, 'civicrm_links');
353 * This hook is invoked during the CiviCRM form preProcess phase.
355 * @param string $formName
356 * The name of the form.
357 * @param CRM_Core_Form $form
358 * Reference to the form object.
361 * the return value is ignored
363 public static function preProcess($formName, &$form) {
364 return self
::singleton()
365 ->invoke(2, $formName, $form, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_preProcess');
369 * This hook is invoked when building a CiviCRM form. This hook should also
370 * be used to set the default values of a form element
372 * @param string $formName
373 * The name of the form.
374 * @param CRM_Core_Form $form
375 * Reference to the form object.
378 * the return value is ignored
380 public static function buildForm($formName, &$form) {
381 return self
::singleton()->invoke(2, $formName, $form,
382 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
388 * This hook is invoked when a CiviCRM form is submitted. If the module has injected
389 * any form elements, this hook should save the values in the database
391 * @param string $formName
392 * The name of the form.
393 * @param CRM_Core_Form $form
394 * Reference to the form object.
397 * the return value is ignored
399 public static function postProcess($formName, &$form) {
400 return self
::singleton()->invoke(2, $formName, $form,
401 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
402 'civicrm_postProcess'
407 * This hook is invoked during all CiviCRM form validation. An array of errors
408 * detected is returned. Else we assume validation succeeded.
410 * @param string $formName
411 * The name of the form.
412 * @param array &$fields the POST parameters as filtered by QF
413 * @param array &$files the FILES parameters as sent in by POST
414 * @param array &$form the form object
415 * @param array &$errors the array of errors.
418 * formRule hooks return a boolean or
419 * an array of error messages which display a QF Error
421 public static function validateForm($formName, &$fields, &$files, &$form, &$errors) {
422 return self
::singleton()
423 ->invoke(5, $formName, $fields, $files, $form, $errors, self
::$_nullObject, 'civicrm_validateForm');
427 * This hook is called after a db write on a custom table.
430 * The type of operation being performed.
431 * @param string $groupID
432 * The custom group ID.
433 * @param object $entityID
434 * The entityID of the row in the custom table.
435 * @param array $params
436 * The parameters that were sent into the calling function.
439 * the return value is ignored
441 public static function custom($op, $groupID, $entityID, &$params) {
442 return self
::singleton()
443 ->invoke(4, $op, $groupID, $entityID, $params, self
::$_nullObject, self
::$_nullObject, 'civicrm_custom');
447 * This hook is called when composing the ACL where clause to restrict
448 * visibility of contacts to the logged in user
451 * The type of permission needed.
452 * @param array $tables
453 * (reference ) add the tables that are needed for the select clause.
454 * @param array $whereTables
455 * (reference ) add the tables that are needed for the where clause.
456 * @param int $contactID
457 * The contactID for whom the check is made.
458 * @param string $where
459 * The currrent where clause.
462 * the return value is ignored
464 public static function aclWhereClause($type, &$tables, &$whereTables, &$contactID, &$where) {
465 return self
::singleton()
466 ->invoke(5, $type, $tables, $whereTables, $contactID, $where, self
::$_nullObject, 'civicrm_aclWhereClause');
470 * This hook is called when composing the ACL where clause to restrict
471 * visibility of contacts to the logged in user
474 * The type of permission needed.
475 * @param int $contactID
476 * The contactID for whom the check is made.
477 * @param string $tableName
478 * The tableName which is being permissioned.
479 * @param array $allGroups
480 * The set of all the objects for the above table.
481 * @param array $currentGroups
482 * The set of objects that are currently permissioned for this contact.
485 * the return value is ignored
487 public static function aclGroup($type, $contactID, $tableName, &$allGroups, &$currentGroups) {
488 return self
::singleton()
489 ->invoke(5, $type, $contactID, $tableName, $allGroups, $currentGroups, self
::$_nullObject, 'civicrm_aclGroup');
493 * This hook is called when building the menu table.
495 * @param array $files
496 * The current set of files to process.
499 * the return value is ignored
501 public static function xmlMenu(&$files) {
502 return self
::singleton()->invoke(1, $files,
503 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
509 * This hook is called for declaring managed entities via API.
511 * @param array $entities
512 * List of pending entities. Each entity is an array with keys:
513 * + '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")
514 * + 'name': string, a symbolic name which can be used to track this entity (Note: Each module creates its own namespace)
515 * + 'entity': string, an entity-type supported by the CiviCRM API (Note: this currently must be an entity which supports the 'is_active' property)
516 * + 'params': array, the entity data as supported by the CiviCRM API
517 * + 'update' (v4.5+): string, a policy which describes when to update records
518 * - 'always' (default): always update the managed-entity record; changes in $entities will override any local changes (eg by the site-admin)
519 * - 'never': never update the managed-entity record; changes made locally (eg by the site-admin) will override changes in $entities
520 * + '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)
521 * - 'always' (default): always delete orphaned records
522 * - 'never': never delete orphaned records
523 * - '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.)
526 * the return value is ignored
528 public static function managed(&$entities) {
529 return self
::singleton()->invoke(1, $entities,
530 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
536 * This hook is called when rendering the dashboard (q=civicrm/dashboard)
538 * @param int $contactID
539 * The contactID for whom the dashboard is being rendered.
540 * @param int $contentPlacement
541 * (output parameter) where should the hook content be displayed.
542 * relative to the activity list
545 * the html snippet to include in the dashboard
547 public static function dashboard($contactID, &$contentPlacement = self
::DASHBOARD_BELOW
) {
548 $retval = self
::singleton()->invoke(2, $contactID, $contentPlacement,
549 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
554 * Note we need this seemingly unnecessary code because in the event that the implementation
555 * of the hook declares the second parameter but doesn't set it, then it comes back unset even
556 * though we have a default value in this function's declaration above.
558 if (!isset($contentPlacement)) {
559 $contentPlacement = self
::DASHBOARD_BELOW
;
566 * This hook is called before storing recently viewed items.
568 * @param array $recentArray
569 * An array of recently viewed or processed items, for in place modification.
573 public static function recent(&$recentArray) {
574 return self
::singleton()->invoke(1, $recentArray,
575 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
581 * Determine how many other records refer to a given record.
583 * @param CRM_Core_DAO $dao
584 * The item for which we want a reference count.
585 * @param array $refCounts
586 * Each item in the array is an Array with keys:
587 * - name: string, eg "sql:civicrm_email:contact_id"
588 * - type: string, eg "sql"
589 * - count: int, eg "5" if there are 5 email addresses that refer to $dao
592 * Return is not really intended to be used.
594 public static function referenceCounts($dao, &$refCounts) {
595 return self
::singleton()->invoke(2, $dao, $refCounts,
596 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
597 'civicrm_referenceCounts'
602 * This hook is called when building the amount structure for a Contribution or Event Page.
604 * @param int $pageType
605 * Is this a contribution or event page.
606 * @param CRM_Core_Form $form
607 * Reference to the form object.
608 * @param array $amount
609 * The amount structure to be displayed.
613 public static function buildAmount($pageType, &$form, &$amount) {
614 return self
::singleton()->invoke(3, $pageType, $form, $amount, self
::$_nullObject,
615 self
::$_nullObject, self
::$_nullObject, 'civicrm_buildAmount');
619 * This hook is called when building the state list for a particular country.
621 * @param array $countryID
622 * The country id whose states are being selected.
627 public static function buildStateProvinceForCountry($countryID, &$states) {
628 return self
::singleton()->invoke(2, $countryID, $states,
629 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
630 'civicrm_buildStateProvinceForCountry'
635 * This hook is called when rendering the tabs for a contact (q=civicrm/contact/view)c
638 * The array of tabs that will be displayed.
639 * @param int $contactID
640 * The contactID for whom the dashboard is being rendered.
643 * @deprecated Use tabset() instead.
645 public static function tabs(&$tabs, $contactID) {
646 return self
::singleton()->invoke(2, $tabs, $contactID,
647 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_tabs'
652 * This hook is called when rendering the tabs used for events and potentially
653 * contribution pages, etc.
655 * @param string $tabsetName
656 * Name of the screen or visual element.
658 * Tabs that will be displayed.
659 * @param array $context
660 * Extra data about the screen or context in which the tab is used.
664 public static function tabset($tabsetName, &$tabs, $context) {
665 return self
::singleton()->invoke(3, $tabsetName, $tabs,
666 $context, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_tabset'
671 * This hook is called when sending an email / printing labels
673 * @param array $tokens
674 * The list of tokens that can be used for the contact.
678 public static function tokens(&$tokens) {
679 return self
::singleton()->invoke(1, $tokens,
680 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_tokens'
685 * This hook is called when sending an email / printing labels to get the values for all the
686 * tokens returned by the 'tokens' hook
688 * @param array $details
689 * The array to store the token values indexed by contactIDs (unless it a single).
690 * @param array $contactIDs
691 * An array of contactIDs.
693 * The jobID if this is associated with a CiviMail mailing.
694 * @param array $tokens
695 * The list of tokens associated with the content.
696 * @param string $className
697 * The top level className from where the hook is invoked.
701 public static function tokenValues(
708 return self
::singleton()
709 ->invoke(5, $details, $contactIDs, $jobID, $tokens, $className, self
::$_nullObject, 'civicrm_tokenValues');
713 * This hook is called before a CiviCRM Page is rendered. You can use this hook to insert smarty variables
716 * @param object $page
717 * The page that will be rendered.
721 public static function pageRun(&$page) {
722 return self
::singleton()->invoke(1, $page,
723 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
729 * This hook is called after a copy of an object has been made. The current objects are
730 * Event, Contribution Page and UFGroup
732 * @param string $objectName
733 * Name of the object.
734 * @param object $object
735 * Reference to the copy.
739 public static function copy($objectName, &$object) {
740 return self
::singleton()->invoke(2, $objectName, $object,
741 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
747 * This hook is called when a contact unsubscribes from a mailing. It allows modules
748 * to override what the contacts are removed from.
752 * @param int $mailingId
753 * The id of the mailing to unsub from
754 * @param int $contactId
755 * The id of the contact who is unsubscribing
756 * @param array|int $groups
757 * Groups the contact will be removed from.
758 * @param array|int $baseGroups
759 * Base groups (used in smart mailings) the contact will be removed from.
764 public static function unsubscribeGroups($op, $mailingId, $contactId, &$groups, &$baseGroups) {
765 return self
::singleton()
766 ->invoke(5, $op, $mailingId, $contactId, $groups, $baseGroups, self
::$_nullObject, 'civicrm_unsubscribeGroups');
770 * This hook is called when CiviCRM needs to edit/display a custom field with options
772 * @deprecated in favor of hook_civicrm_fieldOptions
774 * @param int $customFieldID
775 * The custom field ID.
776 * @param array $options
777 * The current set of options for that custom field.
778 * You can add/remove existing options.
779 * Important: This array may contain meta-data about the field that is needed elsewhere, so it is important
780 * to be careful to not overwrite the array.
781 * Only add/edit/remove the specific field options you intend to affect.
782 * @param bool $detailedFormat
783 * If true, the options are in an ID => array ( 'id' => ID, 'label' => label, 'value' => value ) format
784 * @param array $selectAttributes
785 * Contain select attribute(s) if any.
789 public static function customFieldOptions($customFieldID, &$options, $detailedFormat = FALSE, $selectAttributes = array()) {
790 return self
::singleton()->invoke(3, $customFieldID, $options, $detailedFormat,
791 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
792 'civicrm_customFieldOptions'
797 * Hook for modifying field options
799 * @param string $entity
800 * @param string $field
801 * @param array $options
802 * @param array $params
806 public static function fieldOptions($entity, $field, &$options, $params) {
807 return self
::singleton()->invoke(5, $entity, $field, $options, $params,
808 self
::$_nullObject, self
::$_nullObject,
809 'civicrm_fieldOptions'
815 * This hook is called to display the list of actions allowed after doing a search.
816 * This allows the module developer to inject additional actions or to remove existing actions.
818 * @param string $objectType
819 * The object type for this search.
820 * - activity, campaign, case, contact, contribution, event, grant, membership, and pledge are supported.
821 * @param array $tasks
822 * The current set of tasks for that custom field.
823 * You can add/remove existing tasks.
824 * Each task needs to have a title (eg 'title' => ts( 'Group - add contacts')) and a class
825 * (eg 'class' => 'CRM_Contact_Form_Task_AddToGroup').
826 * Optional result (boolean) may also be provided. Class can be an array of classes (not sure what that does :( ).
827 * The key for new Task(s) should not conflict with the keys for core tasks of that $objectType, which can be
828 * found in CRM/$objectType/Task.php.
832 public static function searchTasks($objectType, &$tasks) {
833 return self
::singleton()->invoke(2, $objectType, $tasks,
834 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
835 'civicrm_searchTasks'
841 * @param array $params
845 public static function eventDiscount(&$form, &$params) {
846 return self
::singleton()->invoke(2, $form, $params,
847 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
848 'civicrm_eventDiscount'
853 * This hook is called when composing a mailing. You can include / exclude other groups as needed.
856 * The form object for which groups / mailings being displayed
857 * @param array $groups
858 * The list of groups being included / excluded
859 * @param array $mailings
860 * The list of mailings being included / excluded
864 public static function mailingGroups(&$form, &$groups, &$mailings) {
865 return self
::singleton()->invoke(3, $form, $groups, $mailings,
866 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
867 'civicrm_mailingGroups'
872 * This hook is called when composing the array of membershipTypes and their cost during a membership registration
874 * Note the hook is called on initial page load and also reloaded after submit (PRG pattern).
875 * You can use it to alter the membership types when first loaded, or after submission
876 * (for example if you want to gather data in the form and use it to alter the fees).
879 * The form object that is presenting the page
880 * @param array $membershipTypes
881 * The array of membership types and their amount
885 public static function membershipTypeValues(&$form, &$membershipTypes) {
886 return self
::singleton()->invoke(2, $form, $membershipTypes,
887 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
888 'civicrm_membershipTypeValues'
893 * This hook is called when rendering the contact summary.
895 * @param int $contactID
896 * The contactID for whom the summary is being rendered
897 * @param mixed $content
898 * @param int $contentPlacement
899 * Specifies where the hook content should be displayed relative to the
903 * The html snippet to include in the contact summary
905 public static function summary($contactID, &$content, &$contentPlacement = self
::SUMMARY_BELOW
) {
906 return self
::singleton()->invoke(3, $contactID, $content, $contentPlacement,
907 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
913 * Use this hook to populate the list of contacts returned by Contact Reference custom fields.
914 * By default, Contact Reference fields will search on and return all CiviCRM contacts.
915 * If you want to limit the contacts returned to a specific group, or some other criteria
916 * - you can override that behavior by providing a SQL query that returns some subset of your contacts.
917 * The hook is called when the query is executed to get the list of contacts to display.
919 * @param mixed $query
920 * - the query that will be executed (input and output parameter);.
921 * It's important to realize that the ACL clause is built prior to this hook being fired,
922 * so your query will ignore any ACL rules that may be defined.
923 * Your query must return two columns:
924 * the contact 'data' to display in the autocomplete dropdown (usually contact.sort_name - aliased as 'data')
926 * @param string $name
927 * The name string to execute the query against (this is the value being typed in by the user).
928 * @param string $context
929 * The context in which this ajax call is being made (for example: 'customfield', 'caseview').
931 * The id of the object for which the call is being made.
932 * For custom fields, it will be the custom field id
936 public static function contactListQuery(&$query, $name, $context, $id) {
937 return self
::singleton()->invoke(4, $query, $name, $context, $id,
938 self
::$_nullObject, self
::$_nullObject,
939 'civicrm_contactListQuery'
944 * Hook definition for altering payment parameters before talking to a payment processor back end.
946 * Definition will look like this:
948 * function hook_civicrm_alterPaymentProcessorParams(
954 * @param CRM_Core_Payment $paymentObj
955 * Instance of payment class of the payment processor invoked (e.g., 'CRM_Core_Payment_Dummy')
956 * See discussion in CRM-16224 as to whether $paymentObj should be passed by reference.
957 * @param array &$rawParams
958 * array of params as passed to to the processor
959 * @param array &$cookedParams
960 * params after the processor code has translated them into its own key/value pairs
963 * This return is not really intended to be used.
965 public static function alterPaymentProcessorParams(
970 return self
::singleton()->invoke(3, $paymentObj, $rawParams, $cookedParams,
971 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
972 'civicrm_alterPaymentProcessorParams'
977 * This hook is called when an email is about to be sent by CiviCRM.
979 * @param array $params
980 * Array fields include: groupName, from, toName, toEmail, subject, cc, bcc, text, html,
981 * returnPath, replyTo, headers, attachments (array)
982 * @param string $context
983 * The context in which the hook is being invoked, eg 'civimail'.
987 public static function alterMailParams(&$params, $context = NULL) {
988 return self
::singleton()->invoke(2, $params, $context,
989 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
990 'civicrm_alterMailParams'
995 * This hook is called when membership status is being calculated.
997 * @param array $membershipStatus
998 * Membership status details as determined - alter if required.
999 * @param array $arguments
1000 * Arguments passed in to calculate date.
1005 * - 'exclude_is_admin'
1006 * - 'membership_type_id'
1007 * @param array $membership
1008 * Membership details from the calling function.
1012 public static function alterCalculatedMembershipStatus(&$membershipStatus, $arguments, $membership) {
1013 return self
::singleton()->invoke(3, $membershipStatus, $arguments,
1014 $membership, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1015 'civicrm_alterCalculatedMembershipStatus'
1020 * This hook is called after getting the content of the mail and before tokenizing it.
1022 * @param array $content
1023 * Array fields include: html, text, subject
1027 public static function alterMailContent(&$content) {
1028 return self
::singleton()->invoke(1, $content,
1029 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1030 'civicrm_alterMailContent'
1035 * This hook is called when rendering the Manage Case screen.
1037 * @param int $caseID
1041 * Array of data to be displayed, where the key is a unique id to be used for styling (div id's)
1042 * and the value is an array with keys 'label' and 'value' specifying label/value pairs
1044 public static function caseSummary($caseID) {
1045 return self
::singleton()->invoke(1, $caseID,
1046 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1047 'civicrm_caseSummary'
1052 * This hook is called when locating CiviCase types.
1054 * @param array $caseTypes
1058 public static function caseTypes(&$caseTypes) {
1059 return self
::singleton()
1060 ->invoke(1, $caseTypes, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_caseTypes');
1064 * This hook is called soon after the CRM_Core_Config object has ben initialized.
1065 * You can use this hook to modify the config object and hence behavior of CiviCRM dynamically.
1067 * @param CRM_Core_Config|array $config
1072 public static function config(&$config) {
1073 return self
::singleton()->invoke(1, $config,
1074 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1080 * This hooks allows to change option values.
1082 * @deprecated in favor of hook_civicrm_fieldOptions
1084 * @param array $options
1085 * Associated array of option values / id
1086 * @param string $name
1091 public static function optionValues(&$options, $name) {
1092 return self
::singleton()->invoke(2, $options, $name,
1093 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1094 'civicrm_optionValues'
1099 * This hook allows modification of the navigation menu.
1101 * @param array $params
1102 * Associated array of navigation menu entry to Modify/Add
1106 public static function navigationMenu(&$params) {
1107 return self
::singleton()->invoke(1, $params,
1108 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1109 'civicrm_navigationMenu'
1114 * This hook allows modification of the data used to perform merging of duplicates.
1116 * @param string $type
1117 * The type of data being passed (cidRefs|eidRefs|relTables|sqls).
1118 * @param array $data
1119 * The data, as described in $type.
1120 * @param int $mainId
1121 * Contact_id of the contact that survives the merge.
1122 * @param int $otherId
1123 * Contact_id of the contact that will be absorbed and deleted.
1124 * @param array $tables
1125 * When $type is "sqls", an array of tables as it may have been handed to the calling function.
1129 public static function merge($type, &$data, $mainId = NULL, $otherId = NULL, $tables = NULL) {
1130 return self
::singleton()->invoke(5, $type, $data, $mainId, $otherId, $tables, self
::$_nullObject, 'civicrm_merge');
1134 * This hook provides a way to override the default privacy behavior for notes.
1136 * @param array &$noteValues
1137 * Associative array of values for this note
1141 public static function notePrivacy(&$noteValues) {
1142 return self
::singleton()->invoke(1, $noteValues,
1143 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1144 'civicrm_notePrivacy'
1149 * This hook is called before record is exported as CSV.
1151 * @param string $exportTempTable
1152 * Name of the temporary export table used during export.
1153 * @param array $headerRows
1154 * Header rows for output.
1155 * @param array $sqlColumns
1157 * @param int $exportMode
1158 * Export mode ( contact, contribution, etc...).
1162 public static function export(&$exportTempTable, &$headerRows, &$sqlColumns, &$exportMode) {
1163 return self
::singleton()->invoke(4, $exportTempTable, $headerRows, $sqlColumns, $exportMode,
1164 self
::$_nullObject, self
::$_nullObject,
1170 * This hook allows modification of the queries constructed from dupe rules.
1172 * @param string $obj
1173 * Object of rulegroup class.
1174 * @param string $type
1175 * Type of queries e.g table / threshold.
1176 * @param array $query
1181 public static function dupeQuery($obj, $type, &$query) {
1182 return self
::singleton()->invoke(3, $obj, $type, $query,
1183 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1189 * This hook is called AFTER EACH email has been processed by the script bin/EmailProcessor.php
1191 * @param string $type
1192 * Type of mail processed: 'activity' OR 'mailing'.
1193 * @param array &$params the params that were sent to the CiviCRM API function
1194 * @param object $mail
1195 * The mail object which is an ezcMail class.
1196 * @param array &$result the result returned by the api call
1197 * @param string $action
1198 * (optional ) the requested action to be performed if the types was 'mailing'.
1202 public static function emailProcessor($type, &$params, $mail, &$result, $action = NULL) {
1203 return self
::singleton()
1204 ->invoke(5, $type, $params, $mail, $result, $action, self
::$_nullObject, 'civicrm_emailProcessor');
1208 * This hook is called after a row has been processed and the
1209 * record (and associated records imported
1211 * @param string $object
1212 * Object being imported (for now Contact only, later Contribution, Activity,.
1213 * Participant and Member)
1214 * @param string $usage
1215 * Hook usage/location (for now process only, later mapping and others).
1216 * @param string $objectRef
1217 * Import record object.
1218 * @param array $params
1219 * Array with various key values: currently.
1220 * contactID - contact id
1221 * importID - row id in temp table
1222 * importTempTable - name of tempTable
1223 * fieldHeaders - field headers
1224 * fields - import fields
1228 public static function import($object, $usage, &$objectRef, &$params) {
1229 return self
::singleton()->invoke(4, $object, $usage, $objectRef, $params,
1230 self
::$_nullObject, self
::$_nullObject,
1236 * This hook is called when API permissions are checked (cf. civicrm_api3_api_check_permission()
1237 * in api/v3/utils.php and _civicrm_api3_permissions() in CRM/Core/DAO/permissions.php).
1239 * @param string $entity
1240 * The API entity (like contact).
1241 * @param string $action
1242 * The API action (like get).
1243 * @param array &$params the API parameters
1244 * @param array &$permissions the associative permissions array (probably to be altered by this hook)
1248 public static function alterAPIPermissions($entity, $action, &$params, &$permissions) {
1249 return self
::singleton()->invoke(4, $entity, $action, $params, $permissions,
1250 self
::$_nullObject, self
::$_nullObject,
1251 'civicrm_alterAPIPermissions'
1256 * @param CRM_Core_DAO $dao
1260 public static function postSave(&$dao) {
1261 $hookName = 'civicrm_postSave_' . $dao->getTableName();
1262 return self
::singleton()->invoke(1, $dao,
1263 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1269 * This hook allows user to customize context menu Actions on contact summary page.
1271 * @param array $actions
1272 * Array of all Actions in contextmenu.
1273 * @param int $contactID
1274 * ContactID for the summary page.
1278 public static function summaryActions(&$actions, $contactID = NULL) {
1279 return self
::singleton()->invoke(2, $actions, $contactID,
1280 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1281 'civicrm_summaryActions'
1286 * This hook is called from CRM_Core_Selector_Controller through which all searches in civicrm go.
1287 * This enables us hook implementors to modify both the headers and the rows
1289 * The BIGGEST drawback with this hook is that you may need to modify the result template to include your
1290 * fields. The result files are CRM/{Contact,Contribute,Member,Event...}/Form/Selector.tpl
1292 * However, if you use the same number of columns, you can overwrite the existing columns with the values that
1293 * you want displayed. This is a hackish, but avoids template modification.
1295 * @param string $objectName
1296 * The component name that we are doing the search.
1297 * activity, campaign, case, contact, contribution, event, grant, membership, and pledge
1298 * @param array &$headers the list of column headers, an associative array with keys: ( name, sort, order )
1299 * @param array &$rows the list of values, an associate array with fields that are displayed for that component
1300 * @param array $selector
1301 * the selector object. Allows you access to the context of the search
1304 * modify the header and values object to pass the data you need
1306 public static function searchColumns($objectName, &$headers, &$rows, &$selector) {
1307 return self
::singleton()->invoke(4, $objectName, $headers, $rows, $selector,
1308 self
::$_nullObject, self
::$_nullObject,
1309 'civicrm_searchColumns'
1314 * This hook is called when uf groups are being built for a module.
1316 * @param string $moduleName
1318 * @param array $ufGroups
1319 * Array of ufgroups for a module.
1323 public static function buildUFGroupsForModule($moduleName, &$ufGroups) {
1324 return self
::singleton()->invoke(2, $moduleName, $ufGroups,
1325 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1326 'civicrm_buildUFGroupsForModule'
1331 * This hook is called when we are determining the contactID for a specific
1334 * @param string $email
1335 * The email address.
1336 * @param int $contactID
1337 * The contactID that matches this email address, IF it exists.
1338 * @param array $result
1339 * (reference) has two fields.
1340 * contactID - the new (or same) contactID
1341 * action - 3 possible values:
1342 * CRM_Utils_Mail_Incoming::EMAILPROCESSOR_CREATE_INDIVIDUAL - create a new contact record
1343 * CRM_Utils_Mail_Incoming::EMAILPROCESSOR_OVERRIDE - use the new contactID
1344 * CRM_Utils_Mail_Incoming::EMAILPROCESSOR_IGNORE - skip this email address
1348 public static function emailProcessorContact($email, $contactID, &$result) {
1349 return self
::singleton()->invoke(3, $email, $contactID, $result,
1350 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1351 'civicrm_emailProcessorContact'
1356 * Hook definition for altering the generation of Mailing Labels.
1358 * @param array $args
1359 * An array of the args in the order defined for the tcpdf multiCell api call.
1360 * with the variable names below converted into string keys (ie $w become 'w'
1361 * as the first key for $args)
1362 * float $w Width of cells. If 0, they extend up to the right margin of the page.
1363 * float $h Cell minimum height. The cell extends automatically if needed.
1364 * string $txt String to print
1365 * mixed $border Indicates if borders must be drawn around the cell block. The value can
1366 * be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or
1367 * a string containing some or all of the following characters (in any order):
1368 * <ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul>
1369 * string $align Allows to center or align the text. Possible values are:<ul><li>L or empty string:
1370 * left align</li><li>C: center</li><li>R: right align</li><li>J: justification
1371 * (default value when $ishtml=false)</li></ul>
1372 * int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
1373 * int $ln Indicates where the current position should go after the call. Possible values are:<ul><li>0:
1374 * to the right</li><li>1: to the beginning of the next line [DEFAULT]</li><li>2: below</li></ul>
1375 * float $x x position in user units
1376 * float $y y position in user units
1377 * boolean $reseth if true reset the last cell height (default true).
1378 * int $stretch stretch character mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if
1379 * necessary</li><li>2 = forced horizontal scaling</li><li>3 = character spacing only if
1380 * necessary</li><li>4 = forced character spacing</li></ul>
1381 * boolean $ishtml set to true if $txt is HTML content (default = false).
1382 * boolean $autopadding if true, uses internal padding and automatically adjust it to account for line width.
1383 * float $maxh maximum height. It should be >= $h and less then remaining space to the bottom of the page,
1384 * or 0 for disable this feature. This feature works only when $ishtml=false.
1388 public static function alterMailingLabelParams(&$args) {
1389 return self
::singleton()->invoke(1, $args,
1390 self
::$_nullObject, self
::$_nullObject,
1391 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1392 'civicrm_alterMailingLabelParams'
1397 * This hooks allows alteration of generated page content.
1400 * Previously generated content.
1402 * Context of content - page or form.
1404 * The file name of the tpl.
1406 * A reference to the page or form object.
1410 public static function alterContent(&$content, $context, $tplName, &$object) {
1411 return self
::singleton()->invoke(4, $content, $context, $tplName, $object,
1412 self
::$_nullObject, self
::$_nullObject,
1413 'civicrm_alterContent'
1418 * This hooks allows alteration of the tpl file used to generate content. It differs from the
1419 * altercontent hook as the content has already been rendered through the tpl at that point
1422 * Previously generated content.
1424 * Reference to the form object.
1426 * Context of content - page or form.
1428 * Reference the file name of the tpl.
1432 public static function alterTemplateFile($formName, &$form, $context, &$tplName) {
1433 return self
::singleton()->invoke(4, $formName, $form, $context, $tplName,
1434 self
::$_nullObject, self
::$_nullObject,
1435 'civicrm_alterTemplateFile'
1440 * This hook collects the trigger definition from all components.
1443 * @param string $tableName
1444 * (optional) the name of the table that we are interested in only.
1446 * @internal param \reference $triggerInfo to an array of trigger information
1447 * each element has 4 fields:
1448 * table - array of tableName
1449 * when - BEFORE or AFTER
1450 * event - array of eventName - INSERT OR UPDATE OR DELETE
1451 * sql - array of statements optionally terminated with a ;
1452 * a statement can use the tokes {tableName} and {eventName}
1453 * to do token replacement with the table / event. This allows
1454 * templatizing logging and other hooks
1457 public static function triggerInfo(&$info, $tableName = NULL) {
1458 return self
::singleton()->invoke(2, $info, $tableName,
1459 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1461 'civicrm_triggerInfo'
1466 * This hook is called when a module-extension is installed.
1467 * Each module will receive hook_civicrm_install during its own installation (but not during the
1468 * installation of unrelated modules).
1470 public static function install() {
1471 return self
::singleton()->invoke(0, self
::$_nullObject,
1472 self
::$_nullObject, self
::$_nullObject,
1473 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1479 * This hook is called when a module-extension is uninstalled.
1480 * Each module will receive hook_civicrm_uninstall during its own uninstallation (but not during the
1481 * uninstallation of unrelated modules).
1483 public static function uninstall() {
1484 return self
::singleton()->invoke(0, self
::$_nullObject,
1485 self
::$_nullObject, self
::$_nullObject,
1486 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1492 * This hook is called when a module-extension is re-enabled.
1493 * Each module will receive hook_civicrm_enable during its own re-enablement (but not during the
1494 * re-enablement of unrelated modules).
1496 public static function enable() {
1497 return self
::singleton()->invoke(0, self
::$_nullObject,
1498 self
::$_nullObject, self
::$_nullObject,
1499 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1505 * This hook is called when a module-extension is disabled.
1506 * Each module will receive hook_civicrm_disable during its own disablement (but not during the
1507 * disablement of unrelated modules).
1509 public static function disable() {
1510 return self
::singleton()->invoke(0, self
::$_nullObject,
1511 self
::$_nullObject, self
::$_nullObject,
1512 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1524 public static function alterReportVar($varType, &$var, &$object) {
1525 return self
::singleton()->invoke(3, $varType, $var, $object,
1527 self
::$_nullObject, self
::$_nullObject,
1528 'civicrm_alterReportVar'
1533 * This hook is called to drive database upgrades for extension-modules.
1536 * The type of operation being performed; 'check' or 'enqueue'.
1537 * @param CRM_Queue_Queue $queue
1538 * (for 'enqueue') the modifiable list of pending up upgrade tasks.
1541 * NULL, if $op is 'enqueue'.
1542 * TRUE, if $op is 'check' and upgrades are pending.
1543 * FALSE, if $op is 'check' and upgrades are not pending.
1545 public static function upgrade($op, CRM_Queue_Queue
$queue = NULL) {
1546 return self
::singleton()->invoke(2, $op, $queue,
1547 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1554 * This hook is called when an email has been successfully sent by CiviCRM, but not on an error.
1556 * @param array $params
1557 * The mailing parameters. Array fields include: groupName, from, toName,
1558 * toEmail, subject, cc, bcc, text, html, returnPath, replyTo, headers,
1559 * attachments (array)
1563 public static function postEmailSend(&$params) {
1564 return self
::singleton()->invoke(1, $params,
1565 self
::$_nullObject, self
::$_nullObject,
1566 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1567 'civicrm_postEmailSend'
1572 * This hook is called when a CiviMail mailing has completed
1574 * @param int $mailingId
1579 public static function postMailing($mailingId) {
1580 return self
::singleton()->invoke(1, $mailingId,
1581 self
::$_nullObject, self
::$_nullObject,
1582 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1583 'civicrm_postMailing'
1588 * This hook is called when Settings specifications are loaded.
1590 * @param array $settingsFolders
1591 * List of paths from which to derive metadata
1595 public static function alterSettingsFolders(&$settingsFolders) {
1596 return self
::singleton()->invoke(1, $settingsFolders,
1597 self
::$_nullObject, self
::$_nullObject,
1598 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1599 'civicrm_alterSettingsFolders'
1604 * This hook is called when Settings have been loaded from the xml
1605 * It is an opportunity for hooks to alter the data
1607 * @param array $settingsMetaData
1608 * Settings Metadata.
1609 * @param int $domainID
1610 * @param mixed $profile
1614 public static function alterSettingsMetaData(&$settingsMetaData, $domainID, $profile) {
1615 return self
::singleton()->invoke(3, $settingsMetaData,
1616 $domainID, $profile,
1617 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1618 'civicrm_alterSettingsMetaData'
1623 * This hook is called before running an api call.
1625 * @param API_Wrapper[] $wrappers
1626 * (see CRM_Utils_API_ReloadOption as an example)
1627 * @param mixed $apiRequest
1630 * The return value is ignored
1632 public static function apiWrappers(&$wrappers, $apiRequest) {
1633 return self
::singleton()
1634 ->invoke(2, $wrappers, $apiRequest, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1635 self
::$_nullObject, 'civicrm_apiWrappers'
1640 * This hook is called before running pending cron jobs.
1642 * @param CRM_Core_JobManager $jobManager
1645 * The return value is ignored.
1647 public static function cron($jobManager) {
1648 return self
::singleton()->invoke(1,
1649 $jobManager, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1655 * This hook is called when loading CMS permissions; use this hook to modify
1656 * the array of system permissions for CiviCRM.
1658 * @param array $permissions
1659 * Array of permissions. See CRM_Core_Permission::getCorePermissions() for
1660 * the format of this array.
1663 * The return value is ignored
1665 public static function permission(&$permissions) {
1666 return self
::singleton()->invoke(1, $permissions,
1667 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1668 'civicrm_permission'
1673 * @param CRM_Core_Exception Exception $exception
1674 * @param mixed $request
1675 * Reserved for future use.
1677 public static function unhandledException($exception, $request = NULL) {
1679 ->invoke(2, $exception, $request, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_unhandled_exception');
1681 // $event = new stdClass();
1682 // $event->exception = $exception;
1683 // CRM_Core_LegacyErrorHandler::handleException($event);
1686 $event = new \Civi\Core\Event\
UnhandledExceptionEvent($exception, self
::$_nullObject);
1687 \Civi
::service('dispatcher')->dispatch("hook_civicrm_unhandled_exception", $event);
1691 * This hook is called for declaring managed entities via API.
1693 * @param array[] $entityTypes
1694 * List of entity types; each entity-type is an array with keys:
1695 * - name: string, a unique short name (e.g. "ReportInstance")
1696 * - class: string, a PHP DAO class (e.g. "CRM_Report_DAO_Instance")
1697 * - table: string, a SQL table name (e.g. "civicrm_report_instance")
1700 * The return value is ignored
1702 public static function entityTypes(&$entityTypes) {
1703 return self
::singleton()->invoke(1, $entityTypes, self
::$_nullObject, self
::$_nullObject,
1704 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_entityTypes'
1709 * This hook is called while preparing a profile form.
1711 * @param string $name
1714 public static function buildProfile($name) {
1715 return self
::singleton()->invoke(1, $name, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1716 self
::$_nullObject, self
::$_nullObject, 'civicrm_buildProfile');
1720 * This hook is called while validating a profile form submission.
1722 * @param string $name
1725 public static function validateProfile($name) {
1726 return self
::singleton()->invoke(1, $name, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1727 self
::$_nullObject, self
::$_nullObject, 'civicrm_validateProfile');
1731 * This hook is called processing a valid profile form submission.
1733 * @param string $name
1736 public static function processProfile($name) {
1737 return self
::singleton()->invoke(1, $name, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1738 self
::$_nullObject, self
::$_nullObject, 'civicrm_processProfile');
1742 * This hook is called while preparing a read-only profile screen
1744 * @param string $name
1747 public static function viewProfile($name) {
1748 return self
::singleton()->invoke(1, $name, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1749 self
::$_nullObject, self
::$_nullObject, 'civicrm_viewProfile');
1753 * This hook is called while preparing a list of contacts (based on a profile)
1755 * @param string $name
1758 public static function searchProfile($name) {
1759 return self
::singleton()->invoke(1, $name, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1760 self
::$_nullObject, self
::$_nullObject, 'civicrm_searchProfile');
1764 * This hook is invoked when building a CiviCRM name badge.
1766 * @param string $labelName
1767 * String referencing name of badge format.
1768 * @param object $label
1769 * Reference to the label object.
1770 * @param array $format
1771 * Array of format data.
1772 * @param array $participant
1773 * Array of participant values.
1776 * the return value is ignored
1778 public static function alterBadge($labelName, &$label, &$format, &$participant) {
1779 return self
::singleton()
1780 ->invoke(4, $labelName, $label, $format, $participant, self
::$_nullObject, self
::$_nullObject, 'civicrm_alterBadge');
1785 * This hook is called before encoding data in barcode.
1787 * @param array $data
1788 * Associated array of values available for encoding.
1789 * @param string $type
1790 * Type of barcode, classic barcode or QRcode.
1791 * @param string $context
1792 * Where this hooks is invoked.
1796 public static function alterBarcode(&$data, $type = 'barcode', $context = 'name_badge') {
1797 return self
::singleton()->invoke(3, $data, $type, $context, self
::$_nullObject,
1798 self
::$_nullObject, self
::$_nullObject, 'civicrm_alterBarcode');
1802 * Modify or replace the Mailer object used for outgoing mail.
1804 * @param object $mailer
1805 * The default mailer produced by normal configuration; a PEAR "Mail" class (like those returned by Mail::factory)
1806 * @param string $driver
1807 * The type of the default mailer (eg "smtp", "sendmail", "mock", "CRM_Mailing_BAO_Spool")
1808 * @param array $params
1809 * The default mailer config options
1812 * @see Mail::factory
1814 public static function alterMailer(&$mailer, $driver, $params) {
1815 return self
::singleton()
1816 ->invoke(3, $mailer, $driver, $params, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_alterMailer');
1820 * Deprecated: Misnamed version of alterMailer(). Remove post-4.7.x.
1821 * Modify or replace the Mailer object used for outgoing mail.
1823 * @param object $mailer
1824 * The default mailer produced by normal configuration; a PEAR "Mail" class (like those returned by Mail::factory)
1825 * @param string $driver
1826 * The type of the default mailer (eg "smtp", "sendmail", "mock", "CRM_Mailing_BAO_Spool")
1827 * @param array $params
1828 * The default mailer config options
1831 * @see Mail::factory
1834 public static function alterMail(&$mailer, $driver, $params) {
1835 return CRM_Utils_Hook
::alterMailer($mailer, $driver, $params);
1839 * This hook is called while building the core search query,
1840 * so hook implementers can provide their own query objects which alters/extends core search.
1842 * @param array $queryObjects
1843 * @param string $type
1847 public static function queryObjects(&$queryObjects, $type = 'Contact') {
1848 return self
::singleton()
1849 ->invoke(2, $queryObjects, $type, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_queryObjects');
1853 * This hook is called while viewing contact dashboard.
1855 * @param array $availableDashlets
1856 * List of dashlets; each is formatted per api/v3/Dashboard
1857 * @param array $defaultDashlets
1858 * List of dashlets; each is formatted per api/v3/DashboardContact
1862 public static function dashboard_defaults($availableDashlets, &$defaultDashlets) {
1863 return self
::singleton()
1864 ->invoke(2, $availableDashlets, $defaultDashlets, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_dashboard_defaults');
1868 * This hook is called before a case merge (or a case reassign)
1870 * @param int $mainContactId
1871 * @param int $mainCaseId
1872 * @param int $otherContactId
1873 * @param int $otherCaseId
1874 * @param bool $changeClient
1878 public static function pre_case_merge($mainContactId, $mainCaseId = NULL, $otherContactId = NULL, $otherCaseId = NULL, $changeClient = FALSE) {
1879 return self
::singleton()
1880 ->invoke(5, $mainContactId, $mainCaseId, $otherContactId, $otherCaseId, $changeClient, self
::$_nullObject, 'civicrm_pre_case_merge');
1884 * This hook is called after a case merge (or a case reassign)
1886 * @param int $mainContactId
1887 * @param int $mainCaseId
1888 * @param int $otherContactId
1889 * @param int $otherCaseId
1890 * @param bool $changeClient
1894 public static function post_case_merge($mainContactId, $mainCaseId = NULL, $otherContactId = NULL, $otherCaseId = NULL, $changeClient = FALSE) {
1895 return self
::singleton()
1896 ->invoke(5, $mainContactId, $mainCaseId, $otherContactId, $otherCaseId, $changeClient, self
::$_nullObject, 'civicrm_post_case_merge');
1901 * Add a hook for altering the display name
1903 * hook_civicrm_contact_get_displayname(&$display_name, $objContact)
1905 * @param string $displayName
1906 * @param int $contactId
1907 * @param object $dao
1908 * The contact object.
1912 public static function alterDisplayName(&$displayName, $contactId, $dao) {
1913 return self
::singleton()->invoke(3,
1914 $displayName, $contactId, $dao, self
::$_nullObject, self
::$_nullObject,
1915 self
::$_nullObject, 'civicrm_contact_get_displayname'
1920 * EXPERIMENTAL: This hook allows one to register additional Angular modules
1922 * @param array $angularModules
1925 * the return value is ignored
1928 * function mymod_civicrm_angularModules(&$angularModules) {
1929 * $angularModules['myAngularModule'] = array(
1930 * 'ext' => 'org.example.mymod',
1931 * 'js' => array('js/myAngularModule.js'),
1933 * $angularModules['myBigAngularModule'] = array(
1934 * 'ext' => 'org.example.mymod',
1935 * 'js' => array('js/part1.js', 'js/part2.js'),
1936 * 'css' => array('css/myAngularModule.css'),
1937 * 'partials' => array('partials/myBigAngularModule'),
1942 public static function angularModules(&$angularModules) {
1943 return self
::singleton()->invoke(1, $angularModules,
1944 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1945 'civicrm_angularModules'
1950 * This hook fires whenever a record in a case changes.
1952 * @param \Civi\CCase\Analyzer $analyzer
1953 * A bundle of data about the case (such as the case and activity records).
1955 public static function caseChange(\Civi\CCase\Analyzer
$analyzer) {
1956 $event = new \Civi\CCase\Event\
CaseChangeEvent($analyzer);
1957 \Civi
::service('dispatcher')->dispatch("hook_civicrm_caseChange", $event);
1959 self
::singleton()->invoke(1, $analyzer,
1960 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1961 'civicrm_caseChange'
1966 * Generate a default CRUD URL for an entity.
1968 * @param array $spec
1970 * - action: int, eg CRM_Core_Action::VIEW or CRM_Core_Action::UPDATE
1971 * - entity_table: string
1973 * @param CRM_Core_DAO $bao
1974 * @param array $link
1975 * To define the link, add these keys to $link:.
1979 * - url: string (used in lieu of "path"/"query")
1980 * Note: if making "url" CRM_Utils_System::url(), set $htmlize=false
1983 public static function crudLink($spec, $bao, &$link) {
1984 return self
::singleton()->invoke(3, $spec, $bao, $link,
1985 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
1991 * Modify the CiviCRM container - add new services, parameters, extensions, etc.
1994 * use Symfony\Component\Config\Resource\FileResource;
1995 * use Symfony\Component\DependencyInjection\Definition;
1997 * function mymodule_civicrm_container($container) {
1998 * $container->addResource(new FileResource(__FILE__));
1999 * $container->setDefinition('mysvc', new Definition('My\Class', array()));
2003 * Tip: The container configuration will be compiled/cached. The default cache
2004 * behavior is aggressive. When you first implement the hook, be sure to
2005 * flush the cache. Additionally, you should relax caching during development.
2006 * In `civicrm.settings.php`, set define('CIVICRM_CONTAINER_CACHE', 'auto').
2008 * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
2009 * @see http://symfony.com/doc/current/components/dependency_injection/index.html
2011 public static function container(\Symfony\Component\DependencyInjection\ContainerBuilder
$container) {
2012 self
::singleton()->invoke(1, $container, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_container');
2016 * @param array <CRM_Core_FileSearchInterface> $fileSearches
2019 public static function fileSearches(&$fileSearches) {
2020 return self
::singleton()->invoke(1, $fileSearches,
2021 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
2022 'civicrm_fileSearches'
2027 * Check system status.
2029 * @param array $messages
2030 * Array<CRM_Utils_Check_Message>. A list of messages regarding system status.
2033 public static function check(&$messages) {
2034 return self
::singleton()
2035 ->invoke(1, $messages, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, 'civicrm_check');
2039 * This hook is called when a query string of the CSV Batch export is generated.
2041 * @param string $query
2045 public static function batchQuery(&$query) {
2046 return self
::singleton()->invoke(1, $query, self
::$_nullObject,
2047 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
2048 'civicrm_batchQuery'
2053 * This hook is called when the entries of the CSV Batch export are mapped.
2055 * @param array $results
2056 * @param array $items
2060 public static function batchItems(&$results, &$items) {
2061 return self
::singleton()->invoke(2, $results, $items,
2062 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
2063 'civicrm_batchItems'
2068 * This hook is called when core resources are being loaded
2070 * @see CRM_Core_Resources::coreResourceList
2072 * @param array $list
2073 * @param string $region
2075 public static function coreResourceList(&$list, $region) {
2076 // First allow the cms integration to add to the list
2077 CRM_Core_Config
::singleton()->userSystem
->appendCoreResources($list);
2079 self
::singleton()->invoke(2, $list, $region,
2080 self
::$_nullObject, self
::$_nullObject, self
::$_nullObject, self
::$_nullObject,
2081 'civicrm_coreResourceList'