Merge pull request #16845 from jitendrapurohit/core-1663
[civicrm-core.git] / CRM / Utils / Hook.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
bc77d7c0
TO
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12/**
13 *
14 * @package CiviCRM_Hook
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035 16 */
6a488035
TO
17abstract class CRM_Utils_Hook {
18
19 // Allowed values for dashboard hook content placement
20 // Default - place content below activity list
7da04cde 21 const DASHBOARD_BELOW = 1;
6a488035 22 // Place content above activity list
7da04cde 23 const DASHBOARD_ABOVE = 2;
6a488035 24 // Don't display activity list at all
7da04cde 25 const DASHBOARD_REPLACE = 3;
6a488035
TO
26
27 // by default - place content below existing content
7da04cde 28 const SUMMARY_BELOW = 1;
50bfb460 29 // place hook content above
7da04cde 30 const SUMMARY_ABOVE = 2;
6714d8d2
SL
31 /**
32 *create your own summaries
33 */
7da04cde 34 const SUMMARY_REPLACE = 3;
6a488035 35
6714d8d2 36 /**
e97c66ff 37 * Object to pass when an object is required to be passed by params.
38 *
39 * This is supposed to be a convenience but note that it is a bad
40 * pattern as it can get contaminated & result in hard-to-diagnose bugs.
41 *
42 * @var null
6714d8d2
SL
43 */
44 public static $_nullObject = NULL;
6a488035
TO
45
46 /**
47 * We only need one instance of this object. So we use the singleton
48 * pattern and cache the instance in this variable
49 *
e97c66ff 50 * @var CRM_Utils_Hook
6a488035
TO
51 */
52 static private $_singleton = NULL;
53
54 /**
55 * @var bool
56 */
57 private $commonIncluded = FALSE;
58
59 /**
ee3db087 60 * @var array|string
6a488035 61 */
be2fb01f 62 private $commonCiviModules = [];
6a488035 63
ad8ccc04
TO
64 /**
65 * @var CRM_Utils_Cache_Interface
66 */
67 protected $cache;
68
6a488035 69 /**
fe482240 70 * Constructor and getter for the singleton instance.
6a488035 71 *
72536736
AH
72 * @param bool $fresh
73 *
e97c66ff 74 * @return CRM_Utils_Hook
72536736 75 * An instance of $config->userHookClass
6a488035 76 */
00be9182 77 public static function singleton($fresh = FALSE) {
6a488035
TO
78 if (self::$_singleton == NULL || $fresh) {
79 $config = CRM_Core_Config::singleton();
80 $class = $config->userHookClass;
6a488035
TO
81 self::$_singleton = new $class();
82 }
83 return self::$_singleton;
84 }
85
f2ac86d1 86 /**
87 * CRM_Utils_Hook constructor.
e97c66ff 88 *
89 * @throws \CRM_Core_Exception
f2ac86d1 90 */
ad8ccc04 91 public function __construct() {
be2fb01f 92 $this->cache = CRM_Utils_Cache::create([
ad8ccc04 93 'name' => 'hooks',
be2fb01f 94 'type' => ['ArrayCache'],
ad8ccc04 95 'prefetch' => 1,
be2fb01f 96 ]);
ad8ccc04
TO
97 }
98
72536736 99 /**
354345c9
TO
100 * Invoke a hook through the UF/CMS hook system and the extension-hook
101 * system.
f0a7a0c9 102 *
77855840
TO
103 * @param int $numParams
104 * Number of parameters to pass to the hook.
105 * @param mixed $arg1
106 * Parameter to be passed to the hook.
107 * @param mixed $arg2
108 * Parameter to be passed to the hook.
109 * @param mixed $arg3
110 * Parameter to be passed to the hook.
111 * @param mixed $arg4
112 * Parameter to be passed to the hook.
113 * @param mixed $arg5
114 * Parameter to be passed to the hook.
115 * @param mixed $arg6
116 * Parameter to be passed to the hook.
117 * @param string $fnSuffix
118 * Function suffix, this is effectively the hook name.
72536736
AH
119 *
120 * @return mixed
121 */
6714d8d2 122 abstract public function invokeViaUF(
a3e55d9c 123 $numParams,
87dab4a4 124 &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6,
6a488035
TO
125 $fnSuffix
126 );
127
354345c9
TO
128 /**
129 * Invoke a hook.
130 *
131 * This is a transitional adapter. It supports the legacy syntax
132 * but also accepts enough information to support Symfony Event
133 * dispatching.
134 *
135 * @param array|int $names
136 * (Recommended) Array of parameter names, in order.
137 * Using an array is recommended because it enables full
138 * event-broadcasting behaviors.
139 * (Legacy) Number of parameters to pass to the hook.
140 * This is provided for transitional purposes.
141 * @param mixed $arg1
142 * @param mixed $arg2
143 * @param mixed $arg3
144 * @param mixed $arg4
145 * @param mixed $arg5
146 * @param mixed $arg6
147 * @param mixed $fnSuffix
148 * @return mixed
149 */
150 public function invoke(
151 $names,
152 &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6,
153 $fnSuffix
154 ) {
62f662b0 155 // Per https://github.com/civicrm/civicrm-core/pull/13551 we have had ongoing significant problems where hooks from modules are
156 // invoked during upgrade but not those from extensions. The issues are both that an incorrect module list & settings are cached and that
157 // some hooks REALLY need to run during upgrade - the loss of triggers during upgrade causes significant loss of data
158 // whereas loss of logTable hooks means that log tables are created for tables specifically excluded - e.g due to large
159 // quantities of low-importance data or the table not having an id field, which could cause a fatal error.
160 // Instead of not calling any hooks we only call those we know to be frequently important - if a particular extension wanted
161 // to avoid this they could do an early return on CRM_Core_Config::singleton()->isUpgradeMode
1b4ddd9d 162 // Futther discussion is happening at https://lab.civicrm.org/dev/core/issues/1460
b5cf5699 163 $upgradeFriendlyHooks = ['civicrm_alterSettingsFolders', 'civicrm_alterSettingsMetaData', 'civicrm_triggerInfo', 'civicrm_alterLogTables', 'civicrm_container', 'civicrm_permission', 'civicrm_managed'];
62f662b0 164 if (CRM_Core_Config::singleton()->isUpgradeMode() && !in_array($fnSuffix, $upgradeFriendlyHooks)) {
165 return;
166 }
4d8e83b6 167 if (is_array($names) && !defined('CIVICRM_FORCE_LEGACY_HOOK') && \Civi\Core\Container::isContainerBooted()) {
e24a07e6
TO
168 $event = \Civi\Core\Event\GenericHookEvent::createOrdered(
169 $names,
170 array(&$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6)
171 );
172 \Civi::dispatcher()->dispatch('hook_' . $fnSuffix, $event);
173 return $event->getReturnValues();
174 }
175 else {
9cf60966 176 // We need to ensure tht we will still run known bootstrap related hooks even if the container is not booted.
bbdc693f 177 $prebootContainerHooks = array_merge($upgradeFriendlyHooks, ['civicrm_entityTypes', 'civicrm_config']);
9cf60966
SL
178 if (!\Civi\Core\Container::isContainerBooted() && !in_array($fnSuffix, $prebootContainerHooks)) {
179 return;
180 }
e24a07e6
TO
181 $count = is_array($names) ? count($names) : $names;
182 return $this->invokeViaUF($count, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $fnSuffix);
183 }
354345c9
TO
184 }
185
5bc392e6 186 /**
100fef9d 187 * @param array $numParams
5bc392e6
EM
188 * @param $arg1
189 * @param $arg2
190 * @param $arg3
191 * @param $arg4
192 * @param $arg5
193 * @param $arg6
194 * @param $fnSuffix
195 * @param $fnPrefix
196 *
197 * @return array|bool
198 */
37cd2432 199 public function commonInvoke(
a3e55d9c 200 $numParams,
87dab4a4 201 &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6,
6a488035
TO
202 $fnSuffix, $fnPrefix
203 ) {
204
205 $this->commonBuildModuleList($fnPrefix);
4636d4fd 206
6a488035 207 return $this->runHooks($this->commonCiviModules, $fnSuffix,
87dab4a4 208 $numParams, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6
6a488035
TO
209 );
210 }
211
212 /**
213 * Build the list of modules to be processed for hooks.
72536736
AH
214 *
215 * @param string $fnPrefix
6a488035 216 */
00be9182 217 public function commonBuildModuleList($fnPrefix) {
6a488035
TO
218 if (!$this->commonIncluded) {
219 // include external file
220 $this->commonIncluded = TRUE;
221
222 $config = CRM_Core_Config::singleton();
5d9bcf01
TO
223 if (!empty($config->customPHPPathDir)) {
224 $civicrmHooksFile = CRM_Utils_File::addTrailingSlash($config->customPHPPathDir) . 'civicrmHooks.php';
225 if (file_exists($civicrmHooksFile)) {
226 @include_once $civicrmHooksFile;
227 }
6a488035
TO
228 }
229
230 if (!empty($fnPrefix)) {
231 $this->commonCiviModules[$fnPrefix] = $fnPrefix;
232 }
233
234 $this->requireCiviModules($this->commonCiviModules);
235 }
236 }
237
72536736 238 /**
e97c66ff 239 * Run hooks.
240 *
241 * @param array $civiModules
242 * @param string $fnSuffix
243 * @param int $numParams
244 * @param mixed $arg1
245 * @param mixed $arg2
246 * @param mixed $arg3
247 * @param mixed $arg4
248 * @param mixed $arg5
249 * @param mixed $arg6
72536736
AH
250 *
251 * @return array|bool
ee3db087 252 * @throws \CRM_Core_Exception
72536736 253 */
37cd2432 254 public function runHooks(
a3e55d9c 255 $civiModules, $fnSuffix, $numParams,
87dab4a4 256 &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6
6a488035 257 ) {
3ac9ab1c
TO
258 // $civiModules is *not* passed by reference because runHooks
259 // must be reentrant. PHP is finicky about running
260 // multiple loops over the same variable. The circumstances
261 // to reproduce the issue are pretty intricate.
be2fb01f 262 $result = [];
6a488035 263
ad8ccc04
TO
264 $fnNames = $this->cache->get($fnSuffix);
265 if (!is_array($fnNames)) {
be2fb01f 266 $fnNames = [];
ad8ccc04
TO
267 if ($civiModules !== NULL) {
268 foreach ($civiModules as $module) {
269 $fnName = "{$module}_{$fnSuffix}";
270 if (function_exists($fnName)) {
271 $fnNames[] = $fnName;
1cba072e 272 }
4636d4fd 273 }
ad8ccc04
TO
274 $this->cache->set($fnSuffix, $fnNames);
275 }
276 }
277
278 foreach ($fnNames as $fnName) {
be2fb01f 279 $fResult = [];
ad8ccc04
TO
280 switch ($numParams) {
281 case 0:
282 $fResult = $fnName();
283 break;
284
285 case 1:
286 $fResult = $fnName($arg1);
287 break;
288
289 case 2:
290 $fResult = $fnName($arg1, $arg2);
291 break;
292
293 case 3:
294 $fResult = $fnName($arg1, $arg2, $arg3);
295 break;
296
297 case 4:
298 $fResult = $fnName($arg1, $arg2, $arg3, $arg4);
299 break;
300
301 case 5:
302 $fResult = $fnName($arg1, $arg2, $arg3, $arg4, $arg5);
303 break;
304
305 case 6:
306 $fResult = $fnName($arg1, $arg2, $arg3, $arg4, $arg5, $arg6);
307 break;
308
309 default:
ee3db087 310 throw new CRM_Core_Exception(ts('Invalid hook invocation'));
ad8ccc04
TO
311 }
312
313 if (!empty($fResult) &&
314 is_array($fResult)
315 ) {
316 $result = array_merge($result, $fResult);
6a488035
TO
317 }
318 }
319
320 return empty($result) ? TRUE : $result;
321 }
322
5bc392e6
EM
323 /**
324 * @param $moduleList
325 */
00be9182 326 public function requireCiviModules(&$moduleList) {
6a488035
TO
327 $civiModules = CRM_Core_PseudoConstant::getModuleExtensions();
328 foreach ($civiModules as $civiModule) {
329 if (!file_exists($civiModule['filePath'])) {
330 CRM_Core_Session::setStatus(
481a74f4 331 ts('Error loading module file (%1). Please restore the file or disable the module.',
be2fb01f 332 [1 => $civiModule['filePath']]),
481a74f4 333 ts('Warning'), 'error');
6a488035
TO
334 continue;
335 }
336 include_once $civiModule['filePath'];
337 $moduleList[$civiModule['prefix']] = $civiModule['prefix'];
6a488035 338 }
e7292422 339 }
6a488035
TO
340
341 /**
342 * This hook is called before a db write on some core objects.
343 * This hook does not allow the abort of the operation
344 *
77855840
TO
345 * @param string $op
346 * The type of operation being performed.
347 * @param string $objectName
348 * The name of the object.
349 * @param int $id
350 * The object id if available.
351 * @param array $params
352 * The parameters used for object creation / editing.
6a488035 353 *
a6c01b45
CW
354 * @return null
355 * the return value is ignored
6a488035 356 */
00be9182 357 public static function pre($op, $objectName, $id, &$params) {
1b4ddd9d
SL
358 // Dev/core#1449 DO not dispatch hook_civicrm_pre if we are in an upgrade as this cases the upgrade to fail
359 // Futher discussion is happening at https://lab.civicrm.org/dev/core/issues/1460
360 if (CRM_Core_Config::singleton()->isUpgradeMode()) {
361 return;
362 }
fd901044 363 $event = new \Civi\Core\Event\PreEvent($op, $objectName, $id, $params);
c73e3098
TO
364 \Civi::dispatcher()->dispatch('hook_civicrm_pre', $event);
365 return $event->getReturnValues();
6a488035
TO
366 }
367
368 /**
369 * This hook is called after a db write on some core objects.
370 *
77855840
TO
371 * @param string $op
372 * The type of operation being performed.
373 * @param string $objectName
374 * The name of the object.
375 * @param int $objectId
376 * The unique identifier for the object.
377 * @param object $objectRef
378 * The reference to the object if available.
6a488035 379 *
72b3a70c
CW
380 * @return mixed
381 * based on op. pre-hooks return a boolean or
6a488035 382 * an error message which aborts the operation
6a488035 383 */
1273d77c 384 public static function post($op, $objectName, $objectId, &$objectRef = NULL) {
1b4ddd9d
SL
385 // Dev/core#1449 DO not dispatch hook_civicrm_post if we are in an upgrade as this cases the upgrade to fail
386 // Futher discussion is happening at https://lab.civicrm.org/dev/core/issues/1460
387 if (CRM_Core_Config::singleton()->isUpgradeMode()) {
388 return;
389 }
fd901044 390 $event = new \Civi\Core\Event\PostEvent($op, $objectName, $objectId, $objectRef);
c73e3098
TO
391 \Civi::dispatcher()->dispatch('hook_civicrm_post', $event);
392 return $event->getReturnValues();
6a488035
TO
393 }
394
74effac4
TO
395 /**
396 * This hook is equivalent to post(), except that it is guaranteed to run
397 * outside of any SQL transaction. The objectRef is not modifiable.
398 *
399 * This hook is defined for two cases:
400 *
401 * 1. If the original action runs within a transaction, then the hook fires
402 * after the transaction commits.
403 * 2. If the original action runs outside a transaction, then the data was
404 * committed immediately, and we can run the hook immediately.
405 *
406 * @param string $op
407 * The type of operation being performed.
408 * @param string $objectName
409 * The name of the object.
410 * @param int $objectId
411 * The unique identifier for the object.
412 * @param object $objectRef
413 * The reference to the object if available.
414 *
415 * @return mixed
416 * based on op. pre-hooks return a boolean or
417 * an error message which aborts the operation
418 */
419 public static function postCommit($op, $objectName, $objectId, $objectRef = NULL) {
420 $event = new \Civi\Core\Event\PostEvent($op, $objectName, $objectId, $objectRef);
421 \Civi::dispatcher()->dispatch('hook_civicrm_postCommit', $event);
422 return $event->getReturnValues();
423 }
424
6a488035 425 /**
fe482240 426 * This hook retrieves links from other modules and injects it into.
6a488035
TO
427 * the view contact tabs
428 *
77855840
TO
429 * @param string $op
430 * The type of operation being performed.
431 * @param string $objectName
432 * The name of the object.
433 * @param int $objectId
434 * The unique identifier for the object.
435 * @param array $links
436 * (optional) the links array (introduced in v3.2).
437 * @param int $mask
438 * (optional) the bitmask to show/hide links.
439 * @param array $values
440 * (optional) the values to fill the links.
6a488035 441 *
a6c01b45
CW
442 * @return null
443 * the return value is ignored
6a488035 444 */
be2fb01f
CW
445 public static function links($op, $objectName, &$objectId, &$links, &$mask = NULL, &$values = []) {
446 return self::singleton()->invoke(['op', 'objectName', 'objectId', 'links', 'mask', 'values'], $op, $objectName, $objectId, $links, $mask, $values, 'civicrm_links');
6a488035
TO
447 }
448
21d2903d
AN
449 /**
450 * This hook is invoked during the CiviCRM form preProcess phase.
451 *
77855840
TO
452 * @param string $formName
453 * The name of the form.
454 * @param CRM_Core_Form $form
455 * Reference to the form object.
21d2903d 456 *
a6c01b45
CW
457 * @return null
458 * the return value is ignored
21d2903d 459 */
00be9182 460 public static function preProcess($formName, &$form) {
37cd2432 461 return self::singleton()
be2fb01f 462 ->invoke(['formName', 'form'], $formName, $form, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_preProcess');
21d2903d
AN
463 }
464
6a488035
TO
465 /**
466 * This hook is invoked when building a CiviCRM form. This hook should also
467 * be used to set the default values of a form element
468 *
77855840
TO
469 * @param string $formName
470 * The name of the form.
471 * @param CRM_Core_Form $form
472 * Reference to the form object.
6a488035 473 *
a6c01b45
CW
474 * @return null
475 * the return value is ignored
6a488035 476 */
00be9182 477 public static function buildForm($formName, &$form) {
be2fb01f 478 return self::singleton()->invoke(['formName', 'form'], $formName, $form,
37cd2432
TO
479 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
480 'civicrm_buildForm'
481 );
6a488035
TO
482 }
483
484 /**
485 * This hook is invoked when a CiviCRM form is submitted. If the module has injected
486 * any form elements, this hook should save the values in the database
487 *
77855840
TO
488 * @param string $formName
489 * The name of the form.
490 * @param CRM_Core_Form $form
491 * Reference to the form object.
6a488035 492 *
a6c01b45
CW
493 * @return null
494 * the return value is ignored
6a488035 495 */
00be9182 496 public static function postProcess($formName, &$form) {
be2fb01f 497 return self::singleton()->invoke(['formName', 'form'], $formName, $form,
37cd2432
TO
498 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
499 'civicrm_postProcess'
500 );
6a488035
TO
501 }
502
503 /**
504 * This hook is invoked during all CiviCRM form validation. An array of errors
6a488035
TO
505 * detected is returned. Else we assume validation succeeded.
506 *
77855840
TO
507 * @param string $formName
508 * The name of the form.
509 * @param array &$fields the POST parameters as filtered by QF
510 * @param array &$files the FILES parameters as sent in by POST
511 * @param array &$form the form object
512 * @param array &$errors the array of errors.
6a488035 513 *
72b3a70c
CW
514 * @return mixed
515 * formRule hooks return a boolean or
6a488035 516 * an array of error messages which display a QF Error
6a488035 517 */
00be9182 518 public static function validateForm($formName, &$fields, &$files, &$form, &$errors) {
37cd2432 519 return self::singleton()
be2fb01f 520 ->invoke(['formName', 'fields', 'files', 'form', 'errors'],
6a8f1687 521 $formName, $fields, $files, $form, $errors, self::$_nullObject, 'civicrm_validateForm');
6a488035
TO
522 }
523
524 /**
42bc70d4 525 * This hook is called after a db write on a custom table.
6a488035 526 *
77855840
TO
527 * @param string $op
528 * The type of operation being performed.
529 * @param string $groupID
530 * The custom group ID.
531 * @param object $entityID
532 * The entityID of the row in the custom table.
533 * @param array $params
534 * The parameters that were sent into the calling function.
6a488035 535 *
a6c01b45
CW
536 * @return null
537 * the return value is ignored
6a488035 538 */
00be9182 539 public static function custom($op, $groupID, $entityID, &$params) {
37cd2432 540 return self::singleton()
be2fb01f 541 ->invoke(['op', 'groupID', 'entityID', 'params'], $op, $groupID, $entityID, $params, self::$_nullObject, self::$_nullObject, 'civicrm_custom');
6a488035
TO
542 }
543
544 /**
545 * This hook is called when composing the ACL where clause to restrict
546 * visibility of contacts to the logged in user
547 *
77855840
TO
548 * @param int $type
549 * The type of permission needed.
550 * @param array $tables
551 * (reference ) add the tables that are needed for the select clause.
552 * @param array $whereTables
553 * (reference ) add the tables that are needed for the where clause.
554 * @param int $contactID
555 * The contactID for whom the check is made.
556 * @param string $where
557 * The currrent where clause.
6a488035 558 *
a6c01b45
CW
559 * @return null
560 * the return value is ignored
6a488035 561 */
00be9182 562 public static function aclWhereClause($type, &$tables, &$whereTables, &$contactID, &$where) {
37cd2432 563 return self::singleton()
be2fb01f 564 ->invoke(['type', 'tables', 'whereTables', 'contactID', 'where'], $type, $tables, $whereTables, $contactID, $where, self::$_nullObject, 'civicrm_aclWhereClause');
6a488035
TO
565 }
566
567 /**
568 * This hook is called when composing the ACL where clause to restrict
569 * visibility of contacts to the logged in user
570 *
77855840
TO
571 * @param int $type
572 * The type of permission needed.
573 * @param int $contactID
574 * The contactID for whom the check is made.
575 * @param string $tableName
576 * The tableName which is being permissioned.
577 * @param array $allGroups
578 * The set of all the objects for the above table.
579 * @param array $currentGroups
580 * The set of objects that are currently permissioned for this contact.
6a488035 581 *
a6c01b45
CW
582 * @return null
583 * the return value is ignored
6a488035 584 */
00be9182 585 public static function aclGroup($type, $contactID, $tableName, &$allGroups, &$currentGroups) {
37cd2432 586 return self::singleton()
be2fb01f 587 ->invoke(['type', 'contactID', 'tableName', 'allGroups', 'currentGroups'], $type, $contactID, $tableName, $allGroups, $currentGroups, self::$_nullObject, 'civicrm_aclGroup');
6a488035
TO
588 }
589
032346cc
CW
590 /**
591 * @param string|CRM_Core_DAO $entity
592 * @param array $clauses
593 * @return mixed
594 */
595 public static function selectWhereClause($entity, &$clauses) {
596 $entityName = is_object($entity) ? _civicrm_api_get_entity_name_from_dao($entity) : $entity;
be2fb01f 597 return self::singleton()->invoke(['entity', 'clauses'], $entityName, $clauses,
032346cc
CW
598 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
599 'civicrm_selectWhereClause'
600 );
601 }
602
6a488035 603 /**
fe482240 604 * This hook is called when building the menu table.
6a488035 605 *
77855840
TO
606 * @param array $files
607 * The current set of files to process.
6a488035 608 *
a6c01b45
CW
609 * @return null
610 * the return value is ignored
6a488035 611 */
00be9182 612 public static function xmlMenu(&$files) {
be2fb01f 613 return self::singleton()->invoke(['files'], $files,
87dab4a4 614 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
6a488035
TO
615 'civicrm_xmlMenu'
616 );
617 }
618
7dc34fb8
TO
619 /**
620 * (Experimental) This hook is called when build the menu table.
621 *
622 * @param array $items
623 * List of records to include in menu table.
624 * @return null
625 * the return value is ignored
626 */
627 public static function alterMenu(&$items) {
be2fb01f 628 return self::singleton()->invoke(['items'], $items,
7dc34fb8
TO
629 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
630 'civicrm_alterMenu'
631 );
632 }
633
d89d2545
TO
634 /**
635 * A theme is a set of CSS files which are loaded on CiviCRM pages. To register a new
636 * theme, add it to the $themes array. Use these properties:
637 *
638 * - ext: string (required)
639 * The full name of the extension which defines the theme.
640 * Ex: "org.civicrm.themes.greenwich".
641 * - title: string (required)
642 * Visible title.
643 * - help: string (optional)
644 * Description of the theme's appearance.
645 * - url_callback: mixed (optional)
646 * A function ($themes, $themeKey, $cssExt, $cssFile) which returns the URL(s) for a CSS resource.
647 * Returns either an array of URLs or PASSTHRU.
648 * Ex: \Civi\Core\Themes\Resolvers::simple (default)
649 * Ex: \Civi\Core\Themes\Resolvers::none
650 * - prefix: string (optional)
651 * A prefix within the extension folder to prepend to the file name.
652 * - search_order: array (optional)
653 * A list of themes to search.
654 * Generally, the last theme should be "*fallback*" (Civi\Core\Themes::FALLBACK).
655 * - excludes: array (optional)
656 * A list of files (eg "civicrm:css/bootstrap.css" or "$ext:$file") which should never
657 * be returned (they are excluded from display).
658 *
659 * @param array $themes
660 * List of themes, keyed by name.
661 * @return null
662 * the return value is ignored
663 */
664 public static function themes(&$themes) {
665 return self::singleton()->invoke(1, $themes,
666 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
667 'civicrm_themes'
668 );
669 }
670
671 /**
672 * The activeTheme hook determines which theme is active.
673 *
674 * @param string $theme
675 * The identifier for the theme. Alterable.
676 * Ex: 'greenwich'.
677 * @param array $context
678 * Information about the current page-request. Includes some mix of:
679 * - page: the relative path of the current Civi page (Ex: 'civicrm/dashboard').
680 * - themes: an instance of the Civi\Core\Themes service.
681 * @return null
682 * the return value is ignored
683 */
684 public static function activeTheme(&$theme, $context) {
685 return self::singleton()->invoke(array('theme', 'context'), $theme, $context,
686 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
687 'civicrm_activeTheme'
688 );
689 }
690
6a488035 691 /**
88718db2 692 * This hook is called for declaring managed entities via API.
6a488035 693 *
77855840 694 * @param array $entities
88718db2
TO
695 * List of pending entities. Each entity is an array with keys:
696 * + '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")
697 * + 'name': string, a symbolic name which can be used to track this entity (Note: Each module creates its own namespace)
698 * + 'entity': string, an entity-type supported by the CiviCRM API (Note: this currently must be an entity which supports the 'is_active' property)
699 * + 'params': array, the entity data as supported by the CiviCRM API
700 * + 'update' (v4.5+): string, a policy which describes when to update records
701 * - 'always' (default): always update the managed-entity record; changes in $entities will override any local changes (eg by the site-admin)
702 * - 'never': never update the managed-entity record; changes made locally (eg by the site-admin) will override changes in $entities
703 * + '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)
704 * - 'always' (default): always delete orphaned records
705 * - 'never': never delete orphaned records
706 * - '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.)
6a488035 707 *
a6c01b45
CW
708 * @return null
709 * the return value is ignored
6a488035 710 */
00be9182 711 public static function managed(&$entities) {
be2fb01f 712 return self::singleton()->invoke(['entities'], $entities,
87dab4a4 713 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
6a488035
TO
714 'civicrm_managed'
715 );
716 }
717
718 /**
719 * This hook is called when rendering the dashboard (q=civicrm/dashboard)
720 *
77855840
TO
721 * @param int $contactID
722 * The contactID for whom the dashboard is being rendered.
723 * @param int $contentPlacement
724 * (output parameter) where should the hook content be displayed.
9399901d 725 * relative to the activity list
6a488035 726 *
a6c01b45
CW
727 * @return string
728 * the html snippet to include in the dashboard
6a488035 729 */
00be9182 730 public static function dashboard($contactID, &$contentPlacement = self::DASHBOARD_BELOW) {
be2fb01f 731 $retval = self::singleton()->invoke(['contactID', 'contentPlacement'], $contactID, $contentPlacement,
87dab4a4 732 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
6a488035
TO
733 'civicrm_dashboard'
734 );
735
736 /*
737 * Note we need this seemingly unnecessary code because in the event that the implementation
738 * of the hook declares the second parameter but doesn't set it, then it comes back unset even
739 * though we have a default value in this function's declaration above.
740 */
741 if (!isset($contentPlacement)) {
742 $contentPlacement = self::DASHBOARD_BELOW;
743 }
744
745 return $retval;
746 }
747
748 /**
749 * This hook is called before storing recently viewed items.
750 *
77855840
TO
751 * @param array $recentArray
752 * An array of recently viewed or processed items, for in place modification.
6a488035
TO
753 *
754 * @return array
6a488035 755 */
00be9182 756 public static function recent(&$recentArray) {
be2fb01f 757 return self::singleton()->invoke(['recentArray'], $recentArray,
87dab4a4 758 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
6a488035
TO
759 'civicrm_recent'
760 );
761 }
762
91dee34b 763 /**
fe482240 764 * Determine how many other records refer to a given record.
91dee34b 765 *
77855840
TO
766 * @param CRM_Core_DAO $dao
767 * The item for which we want a reference count.
768 * @param array $refCounts
16b10e64 769 * Each item in the array is an Array with keys:
91dee34b
TO
770 * - name: string, eg "sql:civicrm_email:contact_id"
771 * - type: string, eg "sql"
772 * - count: int, eg "5" if there are 5 email addresses that refer to $dao
153b262f
EM
773 *
774 * @return mixed
775 * Return is not really intended to be used.
91dee34b 776 */
00be9182 777 public static function referenceCounts($dao, &$refCounts) {
be2fb01f 778 return self::singleton()->invoke(['dao', 'refCounts'], $dao, $refCounts,
91dee34b
TO
779 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
780 'civicrm_referenceCounts'
781 );
782 }
783
6a488035 784 /**
fe482240 785 * This hook is called when building the amount structure for a Contribution or Event Page.
6a488035 786 *
77855840
TO
787 * @param int $pageType
788 * Is this a contribution or event page.
789 * @param CRM_Core_Form $form
790 * Reference to the form object.
791 * @param array $amount
792 * The amount structure to be displayed.
6a488035
TO
793 *
794 * @return null
6a488035 795 */
00be9182 796 public static function buildAmount($pageType, &$form, &$amount) {
be2fb01f 797 return self::singleton()->invoke(['pageType', 'form', 'amount'], $pageType, $form, $amount, self::$_nullObject,
87dab4a4 798 self::$_nullObject, self::$_nullObject, 'civicrm_buildAmount');
6a488035
TO
799 }
800
801 /**
802 * This hook is called when building the state list for a particular country.
803 *
72536736
AH
804 * @param array $countryID
805 * The country id whose states are being selected.
806 * @param $states
6a488035
TO
807 *
808 * @return null
6a488035 809 */
00be9182 810 public static function buildStateProvinceForCountry($countryID, &$states) {
be2fb01f 811 return self::singleton()->invoke(['countryID', 'states'], $countryID, $states,
87dab4a4 812 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
6a488035
TO
813 'civicrm_buildStateProvinceForCountry'
814 );
815 }
816
817 /**
818 * This hook is called when rendering the tabs for a contact (q=civicrm/contact/view)c
819 *
77855840
TO
820 * @param array $tabs
821 * The array of tabs that will be displayed.
822 * @param int $contactID
823 * The contactID for whom the dashboard is being rendered.
6a488035
TO
824 *
825 * @return null
48fe48a6 826 * @deprecated Use tabset() instead.
6a488035 827 */
00be9182 828 public static function tabs(&$tabs, $contactID) {
be2fb01f 829 return self::singleton()->invoke(['tabs', 'contactID'], $tabs, $contactID,
87dab4a4 830 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_tabs'
6a488035
TO
831 );
832 }
833
fa3dbfbd 834 /**
72536736
AH
835 * This hook is called when rendering the tabs used for events and potentially
836 * contribution pages, etc.
837 *
838 * @param string $tabsetName
839 * Name of the screen or visual element.
840 * @param array $tabs
841 * Tabs that will be displayed.
842 * @param array $context
843 * Extra data about the screen or context in which the tab is used.
fa3dbfbd 844 *
2efcf0c2 845 * @return null
fa3dbfbd 846 */
00be9182 847 public static function tabset($tabsetName, &$tabs, $context) {
be2fb01f 848 return self::singleton()->invoke(['tabsetName', 'tabs', 'context'], $tabsetName, $tabs,
87dab4a4 849 $context, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_tabset'
fa3dbfbd 850 );
851 }
852
6a488035
TO
853 /**
854 * This hook is called when sending an email / printing labels
855 *
77855840
TO
856 * @param array $tokens
857 * The list of tokens that can be used for the contact.
6a488035
TO
858 *
859 * @return null
6a488035 860 */
00be9182 861 public static function tokens(&$tokens) {
be2fb01f 862 return self::singleton()->invoke(['tokens'], $tokens,
87dab4a4 863 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_tokens'
6a488035
TO
864 );
865 }
866
8f4eb478 867 /**
868 * This hook allows modification of the admin panels
869 *
870 * @param array $panels
871 * Associated array of admin panels
872 *
873 * @return mixed
874 */
875 public static function alterAdminPanel(&$panels) {
876 return self::singleton()->invoke(array('panels'), $panels,
877 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
878 'civicrm_alterAdminPanel'
879 );
880 }
881
6a488035
TO
882 /**
883 * This hook is called when sending an email / printing labels to get the values for all the
884 * tokens returned by the 'tokens' hook
885 *
77855840
TO
886 * @param array $details
887 * The array to store the token values indexed by contactIDs (unless it a single).
888 * @param array $contactIDs
889 * An array of contactIDs.
890 * @param int $jobID
891 * The jobID if this is associated with a CiviMail mailing.
892 * @param array $tokens
893 * The list of tokens associated with the content.
894 * @param string $className
895 * The top level className from where the hook is invoked.
6a488035
TO
896 *
897 * @return null
6a488035 898 */
37cd2432 899 public static function tokenValues(
a3e55d9c 900 &$details,
6a488035 901 $contactIDs,
e7292422 902 $jobID = NULL,
be2fb01f 903 $tokens = [],
6a488035
TO
904 $className = NULL
905 ) {
37cd2432 906 return self::singleton()
be2fb01f 907 ->invoke(['details', 'contactIDs', 'jobID', 'tokens', 'className'], $details, $contactIDs, $jobID, $tokens, $className, self::$_nullObject, 'civicrm_tokenValues');
6a488035
TO
908 }
909
910 /**
911 * This hook is called before a CiviCRM Page is rendered. You can use this hook to insert smarty variables
912 * in a template
913 *
77855840
TO
914 * @param object $page
915 * The page that will be rendered.
6a488035
TO
916 *
917 * @return null
6a488035 918 */
00be9182 919 public static function pageRun(&$page) {
be2fb01f 920 return self::singleton()->invoke(['page'], $page,
87dab4a4 921 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
6a488035
TO
922 'civicrm_pageRun'
923 );
924 }
925
926 /**
927 * This hook is called after a copy of an object has been made. The current objects are
928 * Event, Contribution Page and UFGroup
929 *
77855840
TO
930 * @param string $objectName
931 * Name of the object.
932 * @param object $object
933 * Reference to the copy.
6a488035
TO
934 *
935 * @return null
6a488035 936 */
00be9182 937 public static function copy($objectName, &$object) {
be2fb01f 938 return self::singleton()->invoke(['objectName', 'object'], $objectName, $object,
87dab4a4 939 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
6a488035
TO
940 'civicrm_copy'
941 );
942 }
943
944 /**
945 * This hook is called when a contact unsubscribes from a mailing. It allows modules
946 * to override what the contacts are removed from.
947 *
72536736
AH
948 * @param string $op
949 * Ignored for now
950 * @param int $mailingId
951 * The id of the mailing to unsub from
952 * @param int $contactId
953 * The id of the contact who is unsubscribing
954 * @param array|int $groups
955 * Groups the contact will be removed from.
956 * @param array|int $baseGroups
957 * Base groups (used in smart mailings) the contact will be removed from.
958 *
dcbd3a55 959 *
72536736
AH
960 * @return mixed
961 */
00be9182 962 public static function unsubscribeGroups($op, $mailingId, $contactId, &$groups, &$baseGroups) {
37cd2432 963 return self::singleton()
be2fb01f 964 ->invoke(['op', 'mailingId', 'contactId', 'groups', 'baseGroups'], $op, $mailingId, $contactId, $groups, $baseGroups, self::$_nullObject, 'civicrm_unsubscribeGroups');
6a488035
TO
965 }
966
967 /**
6eb95671
CW
968 * This hook is called when CiviCRM needs to edit/display a custom field with options
969 *
970 * @deprecated in favor of hook_civicrm_fieldOptions
6a488035 971 *
77855840
TO
972 * @param int $customFieldID
973 * The custom field ID.
974 * @param array $options
975 * The current set of options for that custom field.
6a488035 976 * You can add/remove existing options.
9399901d
KJ
977 * Important: This array may contain meta-data about the field that is needed elsewhere, so it is important
978 * to be careful to not overwrite the array.
6a488035 979 * Only add/edit/remove the specific field options you intend to affect.
77855840 980 * @param bool $detailedFormat
6eb95671 981 * If true, the options are in an ID => array ( 'id' => ID, 'label' => label, 'value' => value ) format
77855840
TO
982 * @param array $selectAttributes
983 * Contain select attribute(s) if any.
72536736
AH
984 *
985 * @return mixed
6a488035 986 */
be2fb01f 987 public static function customFieldOptions($customFieldID, &$options, $detailedFormat = FALSE, $selectAttributes = []) {
9c42b57d 988 // Weird: $selectAttributes is inputted but not outputted.
be2fb01f 989 return self::singleton()->invoke(['customFieldID', 'options', 'detailedFormat'], $customFieldID, $options, $detailedFormat,
87dab4a4 990 self::$_nullObject, self::$_nullObject, self::$_nullObject,
6a488035
TO
991 'civicrm_customFieldOptions'
992 );
993 }
994
33e61cb8
CW
995 /**
996 * Hook for modifying field options
997 *
998 * @param string $entity
999 * @param string $field
1000 * @param array $options
1001 * @param array $params
1002 *
1003 * @return mixed
1004 */
1005 public static function fieldOptions($entity, $field, &$options, $params) {
be2fb01f 1006 return self::singleton()->invoke(['entity', 'field', 'options', 'params'], $entity, $field, $options, $params,
33e61cb8
CW
1007 self::$_nullObject, self::$_nullObject,
1008 'civicrm_fieldOptions'
1009 );
1010 }
1011
6a488035
TO
1012 /**
1013 *
1014 * This hook is called to display the list of actions allowed after doing a search.
1015 * This allows the module developer to inject additional actions or to remove existing actions.
1016 *
77855840
TO
1017 * @param string $objectType
1018 * The object type for this search.
6a488035 1019 * - activity, campaign, case, contact, contribution, event, grant, membership, and pledge are supported.
77855840
TO
1020 * @param array $tasks
1021 * The current set of tasks for that custom field.
6a488035 1022 * You can add/remove existing tasks.
7f82e636 1023 * Each task needs to have a title (eg 'title' => ts( 'Group - add contacts')) and a class
9399901d 1024 * (eg 'class' => 'CRM_Contact_Form_Task_AddToGroup').
6a488035 1025 * Optional result (boolean) may also be provided. Class can be an array of classes (not sure what that does :( ).
9399901d
KJ
1026 * The key for new Task(s) should not conflict with the keys for core tasks of that $objectType, which can be
1027 * found in CRM/$objectType/Task.php.
72536736
AH
1028 *
1029 * @return mixed
6a488035 1030 */
00be9182 1031 public static function searchTasks($objectType, &$tasks) {
be2fb01f 1032 return self::singleton()->invoke(['objectType', 'tasks'], $objectType, $tasks,
87dab4a4 1033 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
6a488035
TO
1034 'civicrm_searchTasks'
1035 );
1036 }
1037
72536736
AH
1038 /**
1039 * @param mixed $form
1040 * @param array $params
1041 *
1042 * @return mixed
1043 */
00be9182 1044 public static function eventDiscount(&$form, &$params) {
be2fb01f 1045 return self::singleton()->invoke(['form', 'params'], $form, $params,
87dab4a4 1046 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
6a488035
TO
1047 'civicrm_eventDiscount'
1048 );
1049 }
1050
1051 /**
1052 * This hook is called when composing a mailing. You can include / exclude other groups as needed.
1053 *
72536736
AH
1054 * @param mixed $form
1055 * The form object for which groups / mailings being displayed
1056 * @param array $groups
1057 * The list of groups being included / excluded
1058 * @param array $mailings
1059 * The list of mailings being included / excluded
1060 *
1061 * @return mixed
6a488035 1062 */
00be9182 1063 public static function mailingGroups(&$form, &$groups, &$mailings) {
be2fb01f 1064 return self::singleton()->invoke(['form', 'groups', 'mailings'], $form, $groups, $mailings,
87dab4a4 1065 self::$_nullObject, self::$_nullObject, self::$_nullObject,
6a488035
TO
1066 'civicrm_mailingGroups'
1067 );
1068 }
1069
703875d8
TO
1070 /**
1071 * (Experimental) Modify the list of template-types used for CiviMail composition.
1072 *
1073 * @param array $types
1074 * Sequentially indexed list of template types. Each type specifies:
1075 * - name: string
1076 * - editorUrl: string, Angular template URL
1077 * - weight: int, priority when picking a default value for new mailings
1078 * @return mixed
1079 */
1080 public static function mailingTemplateTypes(&$types) {
be2fb01f 1081 return self::singleton()->invoke(['types'], $types, self::$_nullObject, self::$_nullObject,
703875d8
TO
1082 self::$_nullObject, self::$_nullObject, self::$_nullObject,
1083 'civicrm_mailingTemplateTypes'
1084 );
1085 }
1086
6a488035 1087 /**
9399901d
KJ
1088 * This hook is called when composing the array of membershipTypes and their cost during a membership registration
1089 * (new or renewal).
6a488035
TO
1090 * Note the hook is called on initial page load and also reloaded after submit (PRG pattern).
1091 * You can use it to alter the membership types when first loaded, or after submission
1092 * (for example if you want to gather data in the form and use it to alter the fees).
1093 *
72536736
AH
1094 * @param mixed $form
1095 * The form object that is presenting the page
1096 * @param array $membershipTypes
1097 * The array of membership types and their amount
1098 *
1099 * @return mixed
6a488035 1100 */
00be9182 1101 public static function membershipTypeValues(&$form, &$membershipTypes) {
be2fb01f 1102 return self::singleton()->invoke(['form', 'membershipTypes'], $form, $membershipTypes,
87dab4a4 1103 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
6a488035
TO
1104 'civicrm_membershipTypeValues'
1105 );
1106 }
1107
1108 /**
fe482240 1109 * This hook is called when rendering the contact summary.
6a488035 1110 *
72536736
AH
1111 * @param int $contactID
1112 * The contactID for whom the summary is being rendered
1113 * @param mixed $content
1114 * @param int $contentPlacement
1115 * Specifies where the hook content should be displayed relative to the
1116 * existing content
6a488035 1117 *
72536736
AH
1118 * @return string
1119 * The html snippet to include in the contact summary
6a488035 1120 */
00be9182 1121 public static function summary($contactID, &$content, &$contentPlacement = self::SUMMARY_BELOW) {
be2fb01f 1122 return self::singleton()->invoke(['contactID', 'content', 'contentPlacement'], $contactID, $content, $contentPlacement,
87dab4a4 1123 self::$_nullObject, self::$_nullObject, self::$_nullObject,
6a488035
TO
1124 'civicrm_summary'
1125 );
1126 }
1127
1128 /**
1129 * Use this hook to populate the list of contacts returned by Contact Reference custom fields.
1130 * By default, Contact Reference fields will search on and return all CiviCRM contacts.
1131 * If you want to limit the contacts returned to a specific group, or some other criteria
1132 * - you can override that behavior by providing a SQL query that returns some subset of your contacts.
1133 * The hook is called when the query is executed to get the list of contacts to display.
1134 *
77855840
TO
1135 * @param mixed $query
1136 * - the query that will be executed (input and output parameter);.
6a488035
TO
1137 * It's important to realize that the ACL clause is built prior to this hook being fired,
1138 * so your query will ignore any ACL rules that may be defined.
1139 * Your query must return two columns:
1140 * the contact 'data' to display in the autocomplete dropdown (usually contact.sort_name - aliased as 'data')
1141 * the contact IDs
0fcad357 1142 * @param string $queryText
77855840
TO
1143 * The name string to execute the query against (this is the value being typed in by the user).
1144 * @param string $context
1145 * The context in which this ajax call is being made (for example: 'customfield', 'caseview').
1146 * @param int $id
1147 * The id of the object for which the call is being made.
6a488035 1148 * For custom fields, it will be the custom field id
72536736
AH
1149 *
1150 * @return mixed
6a488035 1151 */
0fcad357 1152 public static function contactListQuery(&$query, $queryText, $context, $id) {
be2fb01f 1153 return self::singleton()->invoke(['query', 'queryText', 'context', 'id'], $query, $queryText, $context, $id,
87dab4a4 1154 self::$_nullObject, self::$_nullObject,
6a488035
TO
1155 'civicrm_contactListQuery'
1156 );
1157 }
1158
1159 /**
1160 * Hook definition for altering payment parameters before talking to a payment processor back end.
1161 *
1162 * Definition will look like this:
1163 *
153b262f
EM
1164 * function hook_civicrm_alterPaymentProcessorParams(
1165 * $paymentObj,
1166 * &$rawParams,
1167 * &$cookedParams
1168 * );
80bcd255 1169 *
153b262f
EM
1170 * @param CRM_Core_Payment $paymentObj
1171 * Instance of payment class of the payment processor invoked (e.g., 'CRM_Core_Payment_Dummy')
1172 * See discussion in CRM-16224 as to whether $paymentObj should be passed by reference.
6a488035
TO
1173 * @param array &$rawParams
1174 * array of params as passed to to the processor
72536736 1175 * @param array &$cookedParams
6a488035
TO
1176 * params after the processor code has translated them into its own key/value pairs
1177 *
72536736 1178 * @return mixed
80bcd255 1179 * This return is not really intended to be used.
6a488035 1180 */
37cd2432 1181 public static function alterPaymentProcessorParams(
a3e55d9c 1182 $paymentObj,
6a488035
TO
1183 &$rawParams,
1184 &$cookedParams
1185 ) {
be2fb01f 1186 return self::singleton()->invoke(['paymentObj', 'rawParams', 'cookedParams'], $paymentObj, $rawParams, $cookedParams,
87dab4a4 1187 self::$_nullObject, self::$_nullObject, self::$_nullObject,
6a488035
TO
1188 'civicrm_alterPaymentProcessorParams'
1189 );
1190 }
1191
1192 /**
1193 * This hook is called when an email is about to be sent by CiviCRM.
1194 *
72536736
AH
1195 * @param array $params
1196 * Array fields include: groupName, from, toName, toEmail, subject, cc, bcc, text, html,
16b10e64 1197 * returnPath, replyTo, headers, attachments (array)
77855840
TO
1198 * @param string $context
1199 * The context in which the hook is being invoked, eg 'civimail'.
72536736
AH
1200 *
1201 * @return mixed
6a488035 1202 */
00be9182 1203 public static function alterMailParams(&$params, $context = NULL) {
be2fb01f 1204 return self::singleton()->invoke(['params', 'context'], $params, $context,
87dab4a4 1205 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
6a488035
TO
1206 'civicrm_alterMailParams'
1207 );
1208 }
1209
5f11bbcc 1210 /**
fe482240 1211 * This hook is called when membership status is being calculated.
5f11bbcc 1212 *
77855840
TO
1213 * @param array $membershipStatus
1214 * Membership status details as determined - alter if required.
1215 * @param array $arguments
1216 * Arguments passed in to calculate date.
5f11bbcc
EM
1217 * - 'start_date'
1218 * - 'end_date'
1219 * - 'status_date'
1220 * - 'join_date'
1221 * - 'exclude_is_admin'
1222 * - 'membership_type_id'
77855840
TO
1223 * @param array $membership
1224 * Membership details from the calling function.
f4aaa82a
EM
1225 *
1226 * @return mixed
5f11bbcc 1227 */
00be9182 1228 public static function alterCalculatedMembershipStatus(&$membershipStatus, $arguments, $membership) {
be2fb01f 1229 return self::singleton()->invoke(['membershipStatus', 'arguments', 'membership'], $membershipStatus, $arguments,
fc6a608f 1230 $membership, self::$_nullObject, self::$_nullObject, self::$_nullObject,
5f11bbcc
EM
1231 'civicrm_alterCalculatedMembershipStatus'
1232 );
1233 }
1234
d04a3a9b 1235 /**
1236 * This hook is called after getting the content of the mail and before tokenizing it.
1237 *
d1719f82 1238 * @param array $content
d04a3a9b 1239 * Array fields include: html, text, subject
1240 *
1241 * @return mixed
1242 */
d1719f82 1243 public static function alterMailContent(&$content) {
be2fb01f 1244 return self::singleton()->invoke(['content'], $content,
d04a3a9b 1245 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
d1719f82 1246 'civicrm_alterMailContent'
d04a3a9b 1247 );
1248 }
1249
6a488035 1250 /**
fe482240 1251 * This hook is called when rendering the Manage Case screen.
6a488035 1252 *
77855840
TO
1253 * @param int $caseID
1254 * The case ID.
6a488035 1255 *
a6c01b45 1256 * @return array
16b10e64
CW
1257 * Array of data to be displayed, where the key is a unique id to be used for styling (div id's)
1258 * and the value is an array with keys 'label' and 'value' specifying label/value pairs
6a488035 1259 */
00be9182 1260 public static function caseSummary($caseID) {
be2fb01f 1261 return self::singleton()->invoke(['caseID'], $caseID,
87dab4a4 1262 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
6a488035
TO
1263 'civicrm_caseSummary'
1264 );
1265 }
1266
6b86870e
TO
1267 /**
1268 * This hook is called when locating CiviCase types.
1269 *
1270 * @param array $caseTypes
72536736
AH
1271 *
1272 * @return mixed
6b86870e 1273 */
00be9182 1274 public static function caseTypes(&$caseTypes) {
37cd2432 1275 return self::singleton()
be2fb01f 1276 ->invoke(['caseTypes'], $caseTypes, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_caseTypes');
6b86870e
TO
1277 }
1278
6a488035
TO
1279 /**
1280 * This hook is called soon after the CRM_Core_Config object has ben initialized.
1281 * You can use this hook to modify the config object and hence behavior of CiviCRM dynamically.
72536736
AH
1282 *
1283 * @param CRM_Core_Config|array $config
1284 * The config object
1285 *
1286 * @return mixed
6a488035 1287 */
00be9182 1288 public static function config(&$config) {
be2fb01f 1289 return self::singleton()->invoke(['config'], $config,
87dab4a4 1290 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
6a488035
TO
1291 'civicrm_config'
1292 );
1293 }
1294
6a488035 1295 /**
fe482240 1296 * This hooks allows to change option values.
6a488035 1297 *
6eb95671
CW
1298 * @deprecated in favor of hook_civicrm_fieldOptions
1299 *
72536736
AH
1300 * @param array $options
1301 * Associated array of option values / id
0fcad357 1302 * @param string $groupName
72536736 1303 * Option group name
6a488035 1304 *
72536736 1305 * @return mixed
6a488035 1306 */
0fcad357 1307 public static function optionValues(&$options, $groupName) {
be2fb01f 1308 return self::singleton()->invoke(['options', 'groupName'], $options, $groupName,
87dab4a4 1309 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
6a488035
TO
1310 'civicrm_optionValues'
1311 );
1312 }
1313
1314 /**
1315 * This hook allows modification of the navigation menu.
1316 *
72536736
AH
1317 * @param array $params
1318 * Associated array of navigation menu entry to Modify/Add
1319 *
1320 * @return mixed
6a488035 1321 */
00be9182 1322 public static function navigationMenu(&$params) {
be2fb01f 1323 return self::singleton()->invoke(['params'], $params,
87dab4a4 1324 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
6a488035
TO
1325 'civicrm_navigationMenu'
1326 );
1327 }
1328
1329 /**
1330 * This hook allows modification of the data used to perform merging of duplicates.
1331 *
77855840
TO
1332 * @param string $type
1333 * The type of data being passed (cidRefs|eidRefs|relTables|sqls).
1334 * @param array $data
1335 * The data, as described in $type.
1336 * @param int $mainId
1337 * Contact_id of the contact that survives the merge.
1338 * @param int $otherId
1339 * Contact_id of the contact that will be absorbed and deleted.
1340 * @param array $tables
1341 * When $type is "sqls", an array of tables as it may have been handed to the calling function.
6a488035 1342 *
72536736 1343 * @return mixed
6a488035 1344 */
00be9182 1345 public static function merge($type, &$data, $mainId = NULL, $otherId = NULL, $tables = NULL) {
be2fb01f 1346 return self::singleton()->invoke(['type', 'data', 'mainId', 'otherId', 'tables'], $type, $data, $mainId, $otherId, $tables, self::$_nullObject, 'civicrm_merge');
6a488035
TO
1347 }
1348
92a77772 1349 /**
1350 * This hook allows modification of the data calculated for merging locations.
1351 *
1352 * @param array $blocksDAO
1353 * Array of location DAO to be saved. These are arrays in 2 keys 'update' & 'delete'.
1354 * @param int $mainId
1355 * Contact_id of the contact that survives the merge.
1356 * @param int $otherId
1357 * Contact_id of the contact that will be absorbed and deleted.
1358 * @param array $migrationInfo
1359 * Calculated migration info, informational only.
1360 *
1361 * @return mixed
1362 */
1363 public static function alterLocationMergeData(&$blocksDAO, $mainId, $otherId, $migrationInfo) {
be2fb01f 1364 return self::singleton()->invoke(['blocksDAO', 'mainId', 'otherId', 'migrationInfo'], $blocksDAO, $mainId, $otherId, $migrationInfo, self::$_nullObject, self::$_nullObject, 'civicrm_alterLocationMergeData');
92a77772 1365 }
1366
6a488035
TO
1367 /**
1368 * This hook provides a way to override the default privacy behavior for notes.
1369 *
72536736
AH
1370 * @param array &$noteValues
1371 * Associative array of values for this note
6a488035 1372 *
72536736 1373 * @return mixed
6a488035 1374 */
00be9182 1375 public static function notePrivacy(&$noteValues) {
be2fb01f 1376 return self::singleton()->invoke(['noteValues'], $noteValues,
87dab4a4 1377 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
6a488035
TO
1378 'civicrm_notePrivacy'
1379 );
1380 }
1381
1382 /**
fe482240 1383 * This hook is called before record is exported as CSV.
6a488035 1384 *
77855840
TO
1385 * @param string $exportTempTable
1386 * Name of the temporary export table used during export.
1387 * @param array $headerRows
1388 * Header rows for output.
1389 * @param array $sqlColumns
1390 * SQL columns.
1391 * @param int $exportMode
1392 * Export mode ( contact, contribution, etc...).
a09323e9 1393 * @param string $componentTable
1394 * Name of temporary table
1395 * @param array $ids
1396 * Array of object's ids
6a488035 1397 *
72536736 1398 * @return mixed
6a488035 1399 */
ca934663 1400 public static function export(&$exportTempTable, &$headerRows, &$sqlColumns, $exportMode, $componentTable, $ids) {
be2fb01f 1401 return self::singleton()->invoke(['exportTempTable', 'headerRows', 'sqlColumns', 'exportMode', 'componentTable', 'ids'],
a09323e9 1402 $exportTempTable, $headerRows, $sqlColumns,
1403 $exportMode, $componentTable, $ids,
6a488035
TO
1404 'civicrm_export'
1405 );
1406 }
1407
1408 /**
1409 * This hook allows modification of the queries constructed from dupe rules.
1410 *
77855840
TO
1411 * @param string $obj
1412 * Object of rulegroup class.
1413 * @param string $type
1414 * Type of queries e.g table / threshold.
1415 * @param array $query
1416 * Set of queries.
6a488035 1417 *
f4aaa82a 1418 * @return mixed
6a488035 1419 */
00be9182 1420 public static function dupeQuery($obj, $type, &$query) {
be2fb01f 1421 return self::singleton()->invoke(['obj', 'type', 'query'], $obj, $type, $query,
87dab4a4 1422 self::$_nullObject, self::$_nullObject, self::$_nullObject,
6a488035
TO
1423 'civicrm_dupeQuery'
1424 );
1425 }
1426
b8cb7e46
MWMC
1427 /**
1428 * Check for duplicate contacts
1429 *
1430 * @param array $dedupeParams
1431 * Array of params for finding duplicates: [
1432 * '{parameters returned by CRM_Dedupe_Finder::formatParams}
1433 * 'check_permission' => TRUE/FALSE;
1434 * 'contact_type' => $contactType;
1435 * 'rule' = $rule;
1436 * 'rule_group_id' => $ruleGroupID;
1437 * 'excludedContactIDs' => $excludedContactIDs;
1438 * @param array $dedupeResults
1439 * Array of results ['handled' => TRUE/FALSE, 'ids' => array of IDs of duplicate contacts]
1440 * @param array $contextParams
1441 * The context if relevant, eg. ['event_id' => X]
1442 *
1443 * @return mixed
1444 */
1445 public static function findDuplicates($dedupeParams, &$dedupeResults, $contextParams) {
1446 return self::singleton()
be2fb01f 1447 ->invoke(['dedupeParams', 'dedupeResults', 'contextParams'], $dedupeParams, $dedupeResults, $contextParams, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_findDuplicates');
b8cb7e46
MWMC
1448 }
1449
6a488035
TO
1450 /**
1451 * This hook is called AFTER EACH email has been processed by the script bin/EmailProcessor.php
1452 *
77855840
TO
1453 * @param string $type
1454 * Type of mail processed: 'activity' OR 'mailing'.
f4aaa82a 1455 * @param array &$params the params that were sent to the CiviCRM API function
77855840
TO
1456 * @param object $mail
1457 * The mail object which is an ezcMail class.
f4aaa82a 1458 * @param array &$result the result returned by the api call
77855840
TO
1459 * @param string $action
1460 * (optional ) the requested action to be performed if the types was 'mailing'.
6a488035 1461 *
f4aaa82a 1462 * @return mixed
6a488035 1463 */
00be9182 1464 public static function emailProcessor($type, &$params, $mail, &$result, $action = NULL) {
37cd2432 1465 return self::singleton()
be2fb01f 1466 ->invoke(['type', 'params', 'mail', 'result', 'action'], $type, $params, $mail, $result, $action, self::$_nullObject, 'civicrm_emailProcessor');
6a488035
TO
1467 }
1468
1469 /**
1470 * This hook is called after a row has been processed and the
1471 * record (and associated records imported
1472 *
77855840
TO
1473 * @param string $object
1474 * Object being imported (for now Contact only, later Contribution, Activity,.
9399901d 1475 * Participant and Member)
77855840
TO
1476 * @param string $usage
1477 * Hook usage/location (for now process only, later mapping and others).
1478 * @param string $objectRef
1479 * Import record object.
1480 * @param array $params
1481 * Array with various key values: currently.
6a488035
TO
1482 * contactID - contact id
1483 * importID - row id in temp table
1484 * importTempTable - name of tempTable
1485 * fieldHeaders - field headers
1486 * fields - import fields
1487 *
b8c71ffa 1488 * @return mixed
6a488035 1489 */
00be9182 1490 public static function import($object, $usage, &$objectRef, &$params) {
be2fb01f 1491 return self::singleton()->invoke(['object', 'usage', 'objectRef', 'params'], $object, $usage, $objectRef, $params,
87dab4a4 1492 self::$_nullObject, self::$_nullObject,
6a488035
TO
1493 'civicrm_import'
1494 );
1495 }
1496
1497 /**
1498 * This hook is called when API permissions are checked (cf. civicrm_api3_api_check_permission()
aa5ba569 1499 * in api/v3/utils.php and _civicrm_api3_permissions() in CRM/Core/DAO/permissions.php).
6a488035 1500 *
77855840
TO
1501 * @param string $entity
1502 * The API entity (like contact).
1503 * @param string $action
1504 * The API action (like get).
f4aaa82a 1505 * @param array &$params the API parameters
c490a46a 1506 * @param array &$permissions the associative permissions array (probably to be altered by this hook)
f4aaa82a
EM
1507 *
1508 * @return mixed
6a488035 1509 */
00be9182 1510 public static function alterAPIPermissions($entity, $action, &$params, &$permissions) {
be2fb01f 1511 return self::singleton()->invoke(['entity', 'action', 'params', 'permissions'], $entity, $action, $params, $permissions,
87dab4a4 1512 self::$_nullObject, self::$_nullObject,
6a488035
TO
1513 'civicrm_alterAPIPermissions'
1514 );
1515 }
1516
5bc392e6 1517 /**
c490a46a 1518 * @param CRM_Core_DAO $dao
5bc392e6
EM
1519 *
1520 * @return mixed
1521 */
00be9182 1522 public static function postSave(&$dao) {
6a488035 1523 $hookName = 'civicrm_postSave_' . $dao->getTableName();
be2fb01f 1524 return self::singleton()->invoke(['dao'], $dao,
87dab4a4 1525 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
6a488035
TO
1526 $hookName
1527 );
1528 }
1529
1530 /**
1531 * This hook allows user to customize context menu Actions on contact summary page.
1532 *
77855840
TO
1533 * @param array $actions
1534 * Array of all Actions in contextmenu.
1535 * @param int $contactID
1536 * ContactID for the summary page.
f4aaa82a
EM
1537 *
1538 * @return mixed
6a488035 1539 */
00be9182 1540 public static function summaryActions(&$actions, $contactID = NULL) {
be2fb01f 1541 return self::singleton()->invoke(['actions', 'contactID'], $actions, $contactID,
87dab4a4 1542 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
6a488035
TO
1543 'civicrm_summaryActions'
1544 );
1545 }
1546
1547 /**
1548 * This hook is called from CRM_Core_Selector_Controller through which all searches in civicrm go.
1549 * This enables us hook implementors to modify both the headers and the rows
1550 *
1551 * The BIGGEST drawback with this hook is that you may need to modify the result template to include your
1552 * fields. The result files are CRM/{Contact,Contribute,Member,Event...}/Form/Selector.tpl
1553 *
1554 * However, if you use the same number of columns, you can overwrite the existing columns with the values that
1555 * you want displayed. This is a hackish, but avoids template modification.
1556 *
77855840
TO
1557 * @param string $objectName
1558 * The component name that we are doing the search.
6a488035 1559 * activity, campaign, case, contact, contribution, event, grant, membership, and pledge
f4aaa82a
EM
1560 * @param array &$headers the list of column headers, an associative array with keys: ( name, sort, order )
1561 * @param array &$rows the list of values, an associate array with fields that are displayed for that component
16b10e64
CW
1562 * @param array $selector
1563 * the selector object. Allows you access to the context of the search
6a488035 1564 *
b8c71ffa 1565 * @return mixed
50bfb460 1566 * modify the header and values object to pass the data you need
6a488035 1567 */
00be9182 1568 public static function searchColumns($objectName, &$headers, &$rows, &$selector) {
be2fb01f 1569 return self::singleton()->invoke(['objectName', 'headers', 'rows', 'selector'], $objectName, $headers, $rows, $selector,
87dab4a4 1570 self::$_nullObject, self::$_nullObject,
6a488035
TO
1571 'civicrm_searchColumns'
1572 );
1573 }
1574
1575 /**
1576 * This hook is called when uf groups are being built for a module.
1577 *
77855840
TO
1578 * @param string $moduleName
1579 * Module name.
1580 * @param array $ufGroups
1581 * Array of ufgroups for a module.
6a488035
TO
1582 *
1583 * @return null
6a488035 1584 */
00be9182 1585 public static function buildUFGroupsForModule($moduleName, &$ufGroups) {
be2fb01f 1586 return self::singleton()->invoke(['moduleName', 'ufGroups'], $moduleName, $ufGroups,
87dab4a4 1587 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
6a488035
TO
1588 'civicrm_buildUFGroupsForModule'
1589 );
1590 }
1591
1592 /**
1593 * This hook is called when we are determining the contactID for a specific
1594 * email address
1595 *
77855840
TO
1596 * @param string $email
1597 * The email address.
1598 * @param int $contactID
1599 * The contactID that matches this email address, IF it exists.
1600 * @param array $result
1601 * (reference) has two fields.
6a488035
TO
1602 * contactID - the new (or same) contactID
1603 * action - 3 possible values:
9399901d
KJ
1604 * CRM_Utils_Mail_Incoming::EMAILPROCESSOR_CREATE_INDIVIDUAL - create a new contact record
1605 * CRM_Utils_Mail_Incoming::EMAILPROCESSOR_OVERRIDE - use the new contactID
1606 * CRM_Utils_Mail_Incoming::EMAILPROCESSOR_IGNORE - skip this email address
6a488035
TO
1607 *
1608 * @return null
6a488035 1609 */
00be9182 1610 public static function emailProcessorContact($email, $contactID, &$result) {
be2fb01f 1611 return self::singleton()->invoke(['email', 'contactID', 'result'], $email, $contactID, $result,
87dab4a4 1612 self::$_nullObject, self::$_nullObject, self::$_nullObject,
6a488035
TO
1613 'civicrm_emailProcessorContact'
1614 );
1615 }
1616
1617 /**
fe482240 1618 * Hook definition for altering the generation of Mailing Labels.
6a488035 1619 *
77855840
TO
1620 * @param array $args
1621 * An array of the args in the order defined for the tcpdf multiCell api call.
6a488035
TO
1622 * with the variable names below converted into string keys (ie $w become 'w'
1623 * as the first key for $args)
1624 * float $w Width of cells. If 0, they extend up to the right margin of the page.
1625 * float $h Cell minimum height. The cell extends automatically if needed.
1626 * string $txt String to print
1627 * mixed $border Indicates if borders must be drawn around the cell block. The value can
1628 * be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or
1629 * a string containing some or all of the following characters (in any order):
1630 * <ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul>
1631 * string $align Allows to center or align the text. Possible values are:<ul><li>L or empty string:
1632 * left align</li><li>C: center</li><li>R: right align</li><li>J: justification
1633 * (default value when $ishtml=false)</li></ul>
1634 * int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
1635 * int $ln Indicates where the current position should go after the call. Possible values are:<ul><li>0:
1636 * to the right</li><li>1: to the beginning of the next line [DEFAULT]</li><li>2: below</li></ul>
1637 * float $x x position in user units
1638 * float $y y position in user units
1639 * boolean $reseth if true reset the last cell height (default true).
b44e3f84 1640 * int $stretch stretch character mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if
6a488035
TO
1641 * necessary</li><li>2 = forced horizontal scaling</li><li>3 = character spacing only if
1642 * necessary</li><li>4 = forced character spacing</li></ul>
1643 * boolean $ishtml set to true if $txt is HTML content (default = false).
1644 * boolean $autopadding if true, uses internal padding and automatically adjust it to account for line width.
1645 * float $maxh maximum height. It should be >= $h and less then remaining space to the bottom of the page,
1646 * or 0 for disable this feature. This feature works only when $ishtml=false.
1647 *
f4aaa82a 1648 * @return mixed
6a488035 1649 */
00be9182 1650 public static function alterMailingLabelParams(&$args) {
be2fb01f 1651 return self::singleton()->invoke(['args'], $args,
6a488035 1652 self::$_nullObject, self::$_nullObject,
87dab4a4 1653 self::$_nullObject, self::$_nullObject, self::$_nullObject,
6a488035
TO
1654 'civicrm_alterMailingLabelParams'
1655 );
1656 }
1657
1658 /**
fe482240 1659 * This hooks allows alteration of generated page content.
6a488035 1660 *
77855840
TO
1661 * @param $content
1662 * Previously generated content.
1663 * @param $context
1664 * Context of content - page or form.
1665 * @param $tplName
1666 * The file name of the tpl.
1667 * @param $object
1668 * A reference to the page or form object.
6a488035 1669 *
f4aaa82a 1670 * @return mixed
6a488035 1671 */
00be9182 1672 public static function alterContent(&$content, $context, $tplName, &$object) {
be2fb01f 1673 return self::singleton()->invoke(['content', 'context', 'tplName', 'object'], $content, $context, $tplName, $object,
87dab4a4 1674 self::$_nullObject, self::$_nullObject,
6a488035
TO
1675 'civicrm_alterContent'
1676 );
1677 }
1678
8aac22c8 1679 /**
1680 * This hooks allows alteration of the tpl file used to generate content. It differs from the
1681 * altercontent hook as the content has already been rendered through the tpl at that point
1682 *
77855840
TO
1683 * @param $formName
1684 * Previously generated content.
1685 * @param $form
1686 * Reference to the form object.
1687 * @param $context
1688 * Context of content - page or form.
1689 * @param $tplName
1690 * Reference the file name of the tpl.
8aac22c8 1691 *
f4aaa82a 1692 * @return mixed
8aac22c8 1693 */
00be9182 1694 public static function alterTemplateFile($formName, &$form, $context, &$tplName) {
be2fb01f 1695 return self::singleton()->invoke(['formName', 'form', 'context', 'tplName'], $formName, $form, $context, $tplName,
87dab4a4 1696 self::$_nullObject, self::$_nullObject,
8aac22c8 1697 'civicrm_alterTemplateFile'
1698 );
1699 }
f4aaa82a 1700
6a488035 1701 /**
fe482240 1702 * This hook collects the trigger definition from all components.
6a488035 1703 *
f4aaa82a 1704 * @param $info
77855840
TO
1705 * @param string $tableName
1706 * (optional) the name of the table that we are interested in only.
f4aaa82a
EM
1707 *
1708 * @internal param \reference $triggerInfo to an array of trigger information
6a488035
TO
1709 * each element has 4 fields:
1710 * table - array of tableName
1711 * when - BEFORE or AFTER
1712 * event - array of eventName - INSERT OR UPDATE OR DELETE
1713 * sql - array of statements optionally terminated with a ;
1714 * a statement can use the tokes {tableName} and {eventName}
1715 * to do token replacement with the table / event. This allows
1716 * templatizing logging and other hooks
f4aaa82a 1717 * @return mixed
6a488035 1718 */
00be9182 1719 public static function triggerInfo(&$info, $tableName = NULL) {
be2fb01f 1720 return self::singleton()->invoke(['info', 'tableName'], $info, $tableName,
87dab4a4 1721 self::$_nullObject, self::$_nullObject, self::$_nullObject,
6a488035
TO
1722 self::$_nullObject,
1723 'civicrm_triggerInfo'
1724 );
1725 }
6714d8d2 1726
ef587f9c 1727 /**
1728 * This hook allows changes to the spec of which tables to log.
1729 *
1730 * @param array $logTableSpec
1731 *
1732 * @return mixed
1733 */
1734 public static function alterLogTables(&$logTableSpec) {
be2fb01f 1735 return self::singleton()->invoke(['logTableSpec'], $logTableSpec, $_nullObject,
ef587f9c 1736 self::$_nullObject, self::$_nullObject, self::$_nullObject,
1737 self::$_nullObject,
1738 'civicrm_alterLogTables'
1739 );
1740 }
6a488035
TO
1741
1742 /**
1743 * This hook is called when a module-extension is installed.
9399901d
KJ
1744 * Each module will receive hook_civicrm_install during its own installation (but not during the
1745 * installation of unrelated modules).
6a488035 1746 */
00be9182 1747 public static function install() {
6a488035
TO
1748 return self::singleton()->invoke(0, self::$_nullObject,
1749 self::$_nullObject, self::$_nullObject,
87dab4a4 1750 self::$_nullObject, self::$_nullObject, self::$_nullObject,
6a488035
TO
1751 'civicrm_install'
1752 );
1753 }
1754
1755 /**
1756 * This hook is called when a module-extension is uninstalled.
9399901d
KJ
1757 * Each module will receive hook_civicrm_uninstall during its own uninstallation (but not during the
1758 * uninstallation of unrelated modules).
6a488035 1759 */
00be9182 1760 public static function uninstall() {
6a488035
TO
1761 return self::singleton()->invoke(0, self::$_nullObject,
1762 self::$_nullObject, self::$_nullObject,
87dab4a4 1763 self::$_nullObject, self::$_nullObject, self::$_nullObject,
6a488035
TO
1764 'civicrm_uninstall'
1765 );
1766 }
1767
1768 /**
1769 * This hook is called when a module-extension is re-enabled.
9399901d
KJ
1770 * Each module will receive hook_civicrm_enable during its own re-enablement (but not during the
1771 * re-enablement of unrelated modules).
6a488035 1772 */
00be9182 1773 public static function enable() {
6a488035
TO
1774 return self::singleton()->invoke(0, self::$_nullObject,
1775 self::$_nullObject, self::$_nullObject,
87dab4a4 1776 self::$_nullObject, self::$_nullObject, self::$_nullObject,
6a488035
TO
1777 'civicrm_enable'
1778 );
1779 }
1780
1781 /**
1782 * This hook is called when a module-extension is disabled.
9399901d
KJ
1783 * Each module will receive hook_civicrm_disable during its own disablement (but not during the
1784 * disablement of unrelated modules).
6a488035 1785 */
00be9182 1786 public static function disable() {
6a488035
TO
1787 return self::singleton()->invoke(0, self::$_nullObject,
1788 self::$_nullObject, self::$_nullObject,
87dab4a4 1789 self::$_nullObject, self::$_nullObject, self::$_nullObject,
6a488035
TO
1790 'civicrm_disable'
1791 );
1792 }
1793
f9bdf062 1794 /**
1795 * Alter redirect.
1796 *
1797 * This hook is called when the browser is being re-directed and allows the url
1798 * to be altered.
1799 *
1800 * @param \Psr\Http\Message\UriInterface $url
1801 * @param array $context
1802 * Additional information about context
1803 * - output - if this is 'json' then it will return json.
1804 *
1805 * @return null
1806 * the return value is ignored
1807 */
ca4ce861 1808 public static function alterRedirect(&$url, &$context) {
be2fb01f 1809 return self::singleton()->invoke(['url', 'context'], $url,
f9bdf062 1810 $context, self::$_nullObject,
1811 self::$_nullObject, self::$_nullObject, self::$_nullObject,
1812 'civicrm_alterRedirect'
1813 );
1814 }
1815
5bc392e6
EM
1816 /**
1817 * @param $varType
1818 * @param $var
1819 * @param $object
1820 *
1821 * @return mixed
1822 */
00be9182 1823 public static function alterReportVar($varType, &$var, &$object) {
be2fb01f 1824 return self::singleton()->invoke(['varType', 'var', 'object'], $varType, $var, $object,
6a488035 1825 self::$_nullObject,
87dab4a4 1826 self::$_nullObject, self::$_nullObject,
6a488035
TO
1827 'civicrm_alterReportVar'
1828 );
1829 }
1830
1831 /**
1832 * This hook is called to drive database upgrades for extension-modules.
1833 *
72536736
AH
1834 * @param string $op
1835 * The type of operation being performed; 'check' or 'enqueue'.
1836 * @param CRM_Queue_Queue $queue
1837 * (for 'enqueue') the modifiable list of pending up upgrade tasks.
6a488035 1838 *
72536736
AH
1839 * @return bool|null
1840 * NULL, if $op is 'enqueue'.
1841 * TRUE, if $op is 'check' and upgrades are pending.
1842 * FALSE, if $op is 'check' and upgrades are not pending.
6a488035 1843 */
00be9182 1844 public static function upgrade($op, CRM_Queue_Queue $queue = NULL) {
be2fb01f 1845 return self::singleton()->invoke(['op', 'queue'], $op, $queue,
87dab4a4 1846 self::$_nullObject, self::$_nullObject, self::$_nullObject,
6a488035
TO
1847 self::$_nullObject,
1848 'civicrm_upgrade'
1849 );
1850 }
1851
1852 /**
1853 * This hook is called when an email has been successfully sent by CiviCRM, but not on an error.
1854 *
72536736
AH
1855 * @param array $params
1856 * The mailing parameters. Array fields include: groupName, from, toName,
1857 * toEmail, subject, cc, bcc, text, html, returnPath, replyTo, headers,
1858 * attachments (array)
1859 *
1860 * @return mixed
6a488035 1861 */
0870a69e 1862 public static function postEmailSend(&$params) {
be2fb01f 1863 return self::singleton()->invoke(['params'], $params,
6a488035 1864 self::$_nullObject, self::$_nullObject,
0870a69e 1865 self::$_nullObject, self::$_nullObject, self::$_nullObject,
6a488035
TO
1866 'civicrm_postEmailSend'
1867 );
1868 }
1869
0870a69e
BS
1870 /**
1871 * This hook is called when a CiviMail mailing has completed
1872 *
c9a3cf8c
BS
1873 * @param int $mailingId
1874 * Mailing ID
0870a69e
BS
1875 *
1876 * @return mixed
1877 */
c9a3cf8c 1878 public static function postMailing($mailingId) {
be2fb01f 1879 return self::singleton()->invoke(['mailingId'], $mailingId,
0870a69e
BS
1880 self::$_nullObject, self::$_nullObject,
1881 self::$_nullObject, self::$_nullObject, self::$_nullObject,
1882 'civicrm_postMailing'
1883 );
1884 }
1885
6a488035 1886 /**
fe482240 1887 * This hook is called when Settings specifications are loaded.
6a488035 1888 *
72536736
AH
1889 * @param array $settingsFolders
1890 * List of paths from which to derive metadata
1891 *
1892 * @return mixed
6a488035 1893 */
00be9182 1894 public static function alterSettingsFolders(&$settingsFolders) {
be2fb01f 1895 return self::singleton()->invoke(['settingsFolders'], $settingsFolders,
37cd2432
TO
1896 self::$_nullObject, self::$_nullObject,
1897 self::$_nullObject, self::$_nullObject, self::$_nullObject,
1898 'civicrm_alterSettingsFolders'
6a488035
TO
1899 );
1900 }
1901
1902 /**
1903 * This hook is called when Settings have been loaded from the xml
1904 * It is an opportunity for hooks to alter the data
1905 *
77855840
TO
1906 * @param array $settingsMetaData
1907 * Settings Metadata.
72536736
AH
1908 * @param int $domainID
1909 * @param mixed $profile
1910 *
1911 * @return mixed
6a488035 1912 */
00be9182 1913 public static function alterSettingsMetaData(&$settingsMetaData, $domainID, $profile) {
be2fb01f 1914 return self::singleton()->invoke(['settingsMetaData', 'domainID', 'profile'], $settingsMetaData,
37cd2432
TO
1915 $domainID, $profile,
1916 self::$_nullObject, self::$_nullObject, self::$_nullObject,
1917 'civicrm_alterSettingsMetaData'
6a488035
TO
1918 );
1919 }
1920
5270c026
XD
1921 /**
1922 * This hook is called before running an api call.
1923 *
72536736
AH
1924 * @param API_Wrapper[] $wrappers
1925 * (see CRM_Utils_API_ReloadOption as an example)
1926 * @param mixed $apiRequest
5270c026 1927 *
72536736
AH
1928 * @return null
1929 * The return value is ignored
5270c026 1930 */
00be9182 1931 public static function apiWrappers(&$wrappers, $apiRequest) {
09f8c8dc 1932 return self::singleton()
be2fb01f 1933 ->invoke(['wrappers', 'apiRequest'], $wrappers, $apiRequest, self::$_nullObject, self::$_nullObject, self::$_nullObject,
37cd2432
TO
1934 self::$_nullObject, 'civicrm_apiWrappers'
1935 );
5270c026
XD
1936 }
1937
6a488035
TO
1938 /**
1939 * This hook is called before running pending cron jobs.
1940 *
1941 * @param CRM_Core_JobManager $jobManager
1942 *
72536736
AH
1943 * @return null
1944 * The return value is ignored.
6a488035 1945 */
00be9182 1946 public static function cron($jobManager) {
be2fb01f 1947 return self::singleton()->invoke(['jobManager'],
87dab4a4 1948 $jobManager, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
6a488035
TO
1949 'civicrm_cron'
1950 );
1951 }
1952
1953 /**
1954 * This hook is called when loading CMS permissions; use this hook to modify
1955 * the array of system permissions for CiviCRM.
1956 *
72536736
AH
1957 * @param array $permissions
1958 * Array of permissions. See CRM_Core_Permission::getCorePermissions() for
1959 * the format of this array.
6a488035 1960 *
72536736
AH
1961 * @return null
1962 * The return value is ignored
6a488035 1963 */
00be9182 1964 public static function permission(&$permissions) {
be2fb01f 1965 return self::singleton()->invoke(['permissions'], $permissions,
87dab4a4 1966 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
6a488035
TO
1967 'civicrm_permission'
1968 );
1969 }
fed67e4d 1970
3ae62cab
NG
1971 /**
1972 * This hook is called when checking permissions; use this hook to dynamically
1973 * escalate user permissions in certain use cases (cf. CRM-19256).
1974 *
1975 * @param string $permission
1976 * The name of an atomic permission, ie. 'access deleted contacts'
68773b26 1977 * @param bool $granted
3ae62cab 1978 * Whether this permission is currently granted. The hook can change this value.
fa4dac9c
CW
1979 * @param int $contactId
1980 * Contact whose permissions we are checking (if null, assume current user).
3ae62cab
NG
1981 *
1982 * @return null
1983 * The return value is ignored
1984 */
fa4dac9c 1985 public static function permission_check($permission, &$granted, $contactId) {
be2fb01f 1986 return self::singleton()->invoke(['permission', 'granted', 'contactId'], $permission, $granted, $contactId,
fa4dac9c 1987 self::$_nullObject, self::$_nullObject, self::$_nullObject,
3ae62cab
NG
1988 'civicrm_permission_check'
1989 );
1990 }
1991
4b57bc9f 1992 /**
e97c66ff 1993 * @param CRM_Core_Exception $exception
77855840
TO
1994 * @param mixed $request
1995 * Reserved for future use.
4b57bc9f 1996 */
37cd2432 1997 public static function unhandledException($exception, $request = NULL) {
4caeca04 1998 $event = new \Civi\Core\Event\UnhandledExceptionEvent($exception, self::$_nullObject);
c73e3098 1999 \Civi::dispatcher()->dispatch('hook_civicrm_unhandled_exception', $event);
4b57bc9f 2000 }
fed67e4d
TO
2001
2002 /**
fe482240 2003 * This hook is called for declaring managed entities via API.
fed67e4d 2004 *
e97c66ff 2005 * Note: This is a pre-boot hook. It will dispatch via the extension/module
4d8e83b6
TO
2006 * subsystem but *not* the Symfony EventDispatcher.
2007 *
72536736
AH
2008 * @param array[] $entityTypes
2009 * List of entity types; each entity-type is an array with keys:
fed67e4d
TO
2010 * - name: string, a unique short name (e.g. "ReportInstance")
2011 * - class: string, a PHP DAO class (e.g. "CRM_Report_DAO_Instance")
2012 * - table: string, a SQL table name (e.g. "civicrm_report_instance")
740dd877
TO
2013 * - fields_callback: array, list of callables which manipulates field list
2014 * - links_callback: array, list of callables which manipulates fk list
fed67e4d 2015 *
72536736
AH
2016 * @return null
2017 * The return value is ignored
fed67e4d 2018 */
00be9182 2019 public static function entityTypes(&$entityTypes) {
be2fb01f 2020 return self::singleton()->invoke(['entityTypes'], $entityTypes, self::$_nullObject, self::$_nullObject,
87dab4a4 2021 self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_entityTypes'
fed67e4d
TO
2022 );
2023 }
a8387f19 2024
bdd65b5c
TO
2025 /**
2026 * Build a description of available hooks.
2027 *
ec84755a 2028 * @param \Civi\Core\CiviEventInspector $inspector
bdd65b5c 2029 */
47e7c2f8 2030 public static function eventDefs($inspector) {
be2fb01f 2031 $event = \Civi\Core\Event\GenericHookEvent::create([
00932067 2032 'inspector' => $inspector,
be2fb01f 2033 ]);
47e7c2f8 2034 Civi::dispatcher()->dispatch('hook_civicrm_eventDefs', $event);
bdd65b5c
TO
2035 }
2036
a8387f19 2037 /**
fe482240 2038 * This hook is called while preparing a profile form.
a8387f19 2039 *
0fcad357 2040 * @param string $profileName
72536736 2041 * @return mixed
a8387f19 2042 */
0fcad357 2043 public static function buildProfile($profileName) {
be2fb01f 2044 return self::singleton()->invoke(['profileName'], $profileName, self::$_nullObject, self::$_nullObject, self::$_nullObject,
87dab4a4 2045 self::$_nullObject, self::$_nullObject, 'civicrm_buildProfile');
a8387f19
TO
2046 }
2047
2048 /**
fe482240 2049 * This hook is called while validating a profile form submission.
a8387f19 2050 *
0fcad357 2051 * @param string $profileName
72536736 2052 * @return mixed
a8387f19 2053 */
0fcad357 2054 public static function validateProfile($profileName) {
be2fb01f 2055 return self::singleton()->invoke(['profileName'], $profileName, self::$_nullObject, self::$_nullObject, self::$_nullObject,
87dab4a4 2056 self::$_nullObject, self::$_nullObject, 'civicrm_validateProfile');
a8387f19
TO
2057 }
2058
2059 /**
fe482240 2060 * This hook is called processing a valid profile form submission.
a8387f19 2061 *
0fcad357 2062 * @param string $profileName
72536736 2063 * @return mixed
a8387f19 2064 */
0fcad357 2065 public static function processProfile($profileName) {
be2fb01f 2066 return self::singleton()->invoke(['profileName'], $profileName, self::$_nullObject, self::$_nullObject, self::$_nullObject,
87dab4a4 2067 self::$_nullObject, self::$_nullObject, 'civicrm_processProfile');
a8387f19
TO
2068 }
2069
2070 /**
2071 * This hook is called while preparing a read-only profile screen
2072 *
0fcad357 2073 * @param string $profileName
72536736 2074 * @return mixed
a8387f19 2075 */
0fcad357 2076 public static function viewProfile($profileName) {
be2fb01f 2077 return self::singleton()->invoke(['profileName'], $profileName, self::$_nullObject, self::$_nullObject, self::$_nullObject,
87dab4a4 2078 self::$_nullObject, self::$_nullObject, 'civicrm_viewProfile');
a8387f19
TO
2079 }
2080
2081 /**
2082 * This hook is called while preparing a list of contacts (based on a profile)
2083 *
0fcad357 2084 * @param string $profileName
72536736 2085 * @return mixed
a8387f19 2086 */
0fcad357 2087 public static function searchProfile($profileName) {
be2fb01f 2088 return self::singleton()->invoke(['profileName'], $profileName, self::$_nullObject, self::$_nullObject, self::$_nullObject,
87dab4a4 2089 self::$_nullObject, self::$_nullObject, 'civicrm_searchProfile');
9399901d
KJ
2090 }
2091
d0fc33e2
M
2092 /**
2093 * This hook is invoked when building a CiviCRM name badge.
2094 *
77855840
TO
2095 * @param string $labelName
2096 * String referencing name of badge format.
2097 * @param object $label
2098 * Reference to the label object.
2099 * @param array $format
2100 * Array of format data.
2101 * @param array $participant
2102 * Array of participant values.
d0fc33e2 2103 *
a6c01b45
CW
2104 * @return null
2105 * the return value is ignored
d0fc33e2 2106 */
00be9182 2107 public static function alterBadge($labelName, &$label, &$format, &$participant) {
37cd2432 2108 return self::singleton()
be2fb01f 2109 ->invoke(['labelName', 'label', 'format', 'participant'], $labelName, $label, $format, $participant, self::$_nullObject, self::$_nullObject, 'civicrm_alterBadge');
d0fc33e2
M
2110 }
2111
9399901d 2112 /**
fe482240 2113 * This hook is called before encoding data in barcode.
9399901d 2114 *
77855840
TO
2115 * @param array $data
2116 * Associated array of values available for encoding.
2117 * @param string $type
2118 * Type of barcode, classic barcode or QRcode.
2119 * @param string $context
2120 * Where this hooks is invoked.
9399901d 2121 *
72536736 2122 * @return mixed
9399901d 2123 */
e7292422 2124 public static function alterBarcode(&$data, $type = 'barcode', $context = 'name_badge') {
be2fb01f 2125 return self::singleton()->invoke(['data', 'type', 'context'], $data, $type, $context, self::$_nullObject,
87dab4a4 2126 self::$_nullObject, self::$_nullObject, 'civicrm_alterBarcode');
a8387f19 2127 }
99e9587a 2128
72ad6c1b
TO
2129 /**
2130 * Modify or replace the Mailer object used for outgoing mail.
2131 *
2132 * @param object $mailer
2133 * The default mailer produced by normal configuration; a PEAR "Mail" class (like those returned by Mail::factory)
2134 * @param string $driver
2135 * The type of the default mailer (eg "smtp", "sendmail", "mock", "CRM_Mailing_BAO_Spool")
2136 * @param array $params
2137 * The default mailer config options
72536736
AH
2138 *
2139 * @return mixed
72ad6c1b
TO
2140 * @see Mail::factory
2141 */
f2b63bd3 2142 public static function alterMailer(&$mailer, $driver, $params) {
c8e4bea0 2143 return self::singleton()
be2fb01f 2144 ->invoke(['mailer', 'driver', 'params'], $mailer, $driver, $params, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_alterMailer');
72ad6c1b
TO
2145 }
2146
99e9587a 2147 /**
2efcf0c2 2148 * This hook is called while building the core search query,
99e9587a
DS
2149 * so hook implementers can provide their own query objects which alters/extends core search.
2150 *
72536736
AH
2151 * @param array $queryObjects
2152 * @param string $type
2153 *
2154 * @return mixed
99e9587a 2155 */
00be9182 2156 public static function queryObjects(&$queryObjects, $type = 'Contact') {
37cd2432 2157 return self::singleton()
be2fb01f 2158 ->invoke(['queryObjects', 'type'], $queryObjects, $type, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_queryObjects');
99e9587a 2159 }
15d9b3ae
N
2160
2161 /**
fe482240 2162 * This hook is called while viewing contact dashboard.
15d9b3ae 2163 *
72536736
AH
2164 * @param array $availableDashlets
2165 * List of dashlets; each is formatted per api/v3/Dashboard
2166 * @param array $defaultDashlets
2167 * List of dashlets; each is formatted per api/v3/DashboardContact
2168 *
2169 * @return mixed
15d9b3ae 2170 */
00be9182 2171 public static function dashboard_defaults($availableDashlets, &$defaultDashlets) {
37cd2432 2172 return self::singleton()
be2fb01f 2173 ->invoke(['availableDashlets', 'defaultDashlets'], $availableDashlets, $defaultDashlets, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_dashboard_defaults');
15d9b3ae 2174 }
02094cdb
JJ
2175
2176 /**
2177 * This hook is called before a case merge (or a case reassign)
f4aaa82a 2178 *
77855840
TO
2179 * @param int $mainContactId
2180 * @param int $mainCaseId
2181 * @param int $otherContactId
2182 * @param int $otherCaseId
3d0d359e 2183 * @param bool $changeClient
f4aaa82a 2184 *
b8c71ffa 2185 * @return mixed
02094cdb 2186 */
00be9182 2187 public static function pre_case_merge($mainContactId, $mainCaseId = NULL, $otherContactId = NULL, $otherCaseId = NULL, $changeClient = FALSE) {
37cd2432 2188 return self::singleton()
be2fb01f 2189 ->invoke(['mainContactId', 'mainCaseId', 'otherContactId', 'otherCaseId', 'changeClient'], $mainContactId, $mainCaseId, $otherContactId, $otherCaseId, $changeClient, self::$_nullObject, 'civicrm_pre_case_merge');
02094cdb 2190 }
f4aaa82a 2191
02094cdb
JJ
2192 /**
2193 * This hook is called after a case merge (or a case reassign)
f4aaa82a 2194 *
77855840
TO
2195 * @param int $mainContactId
2196 * @param int $mainCaseId
2197 * @param int $otherContactId
2198 * @param int $otherCaseId
3d0d359e 2199 * @param bool $changeClient
77b97be7 2200 *
b8c71ffa 2201 * @return mixed
02094cdb 2202 */
00be9182 2203 public static function post_case_merge($mainContactId, $mainCaseId = NULL, $otherContactId = NULL, $otherCaseId = NULL, $changeClient = FALSE) {
37cd2432 2204 return self::singleton()
be2fb01f 2205 ->invoke(['mainContactId', 'mainCaseId', 'otherContactId', 'otherCaseId', 'changeClient'], $mainContactId, $mainCaseId, $otherContactId, $otherCaseId, $changeClient, self::$_nullObject, 'civicrm_post_case_merge');
02094cdb 2206 }
250b3b1f 2207
2208 /**
2209 * Issue CRM-14276
2210 * Add a hook for altering the display name
2211 *
2212 * hook_civicrm_contact_get_displayname(&$display_name, $objContact)
f4aaa82a 2213 *
250b3b1f 2214 * @param string $displayName
2215 * @param int $contactId
77855840
TO
2216 * @param object $dao
2217 * The contact object.
f4aaa82a
EM
2218 *
2219 * @return mixed
250b3b1f 2220 */
267578ea 2221 public static function alterDisplayName(&$displayName, $contactId, $dao) {
be2fb01f 2222 return self::singleton()->invoke(['displayName', 'contactId', 'dao'],
250b3b1f 2223 $displayName, $contactId, $dao, self::$_nullObject, self::$_nullObject,
2224 self::$_nullObject, 'civicrm_contact_get_displayname'
2225 );
2226 }
e7ff7042 2227
898951c6
TO
2228 /**
2229 * Modify the CRM_Core_Resources settings data.
2230 *
2231 * @param array $data
2232 * @see CRM_Core_Resources::addSetting
2233 */
2234 public static function alterResourceSettings(&$data) {
be2fb01f 2235 $event = \Civi\Core\Event\GenericHookEvent::create([
898951c6 2236 'data' => &$data,
be2fb01f 2237 ]);
898951c6
TO
2238 Civi::dispatcher()->dispatch('hook_civicrm_alterResourceSettings', $event);
2239 }
2240
e7ff7042
TO
2241 /**
2242 * EXPERIMENTAL: This hook allows one to register additional Angular modules
2243 *
77855840 2244 * @param array $angularModules
5438399c
TO
2245 * List of modules. Each module defines:
2246 * - ext: string, the CiviCRM extension which hosts the files.
2247 * - js: array, list of JS files or globs.
2248 * - css: array, list of CSS files or globs.
2249 * - partials: array, list of base-dirs containing HTML.
90c62ad3
TO
2250 * - partialsCallback: mixed, a callback function which generates a list of HTML
2251 * function(string $moduleName, array $moduleDefn) => array(string $file => string $html)
2252 * For future-proofing, use a serializable callback (e.g. string/array).
2253 * See also: Civi\Core\Resolver.
5438399c 2254 * - requires: array, list of required Angular modules.
8da6c9b8
TO
2255 * - basePages: array, uncondtionally load this module onto the given Angular pages. [v4.7.21+]
2256 * If omitted, default to "array('civicrm/a')" for backward compat.
2257 * For a utility that should only be loaded on-demand, use "array()".
2258 * For a utility that should be loaded in all pages use, "array('*')".
a6c01b45
CW
2259 * @return null
2260 * the return value is ignored
e7ff7042
TO
2261 *
2262 * @code
2263 * function mymod_civicrm_angularModules(&$angularModules) {
8671b4f2
TO
2264 * $angularModules['myAngularModule'] = array(
2265 * 'ext' => 'org.example.mymod',
2266 * 'js' => array('js/myAngularModule.js'),
2267 * );
2268 * $angularModules['myBigAngularModule'] = array(
2269 * 'ext' => 'org.example.mymod',
e5c376e7
TO
2270 * 'js' => array('js/part1.js', 'js/part2.js', 'ext://other.ext.name/file.js', 'assetBuilder://dynamicAsset.js'),
2271 * 'css' => array('css/myAngularModule.css', 'ext://other.ext.name/file.css', 'assetBuilder://dynamicAsset.css'),
8671b4f2 2272 * 'partials' => array('partials/myBigAngularModule'),
5438399c 2273 * 'requires' => array('otherModuleA', 'otherModuleB'),
8da6c9b8 2274 * 'basePages' => array('civicrm/a'),
8671b4f2 2275 * );
e7ff7042
TO
2276 * }
2277 * @endcode
2278 */
00be9182 2279 public static function angularModules(&$angularModules) {
be2fb01f 2280 return self::singleton()->invoke(['angularModules'], $angularModules,
e7ff7042
TO
2281 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
2282 'civicrm_angularModules'
2283 );
2284 }
2285
6dc348de
TO
2286 /**
2287 * Alter the definition of some Angular HTML partials.
2288 *
2289 * @param \Civi\Angular\Manager $angular
2290 *
2291 * @code
2292 * function example_civicrm_alterAngular($angular) {
f895c70e 2293 * $changeSet = \Civi\Angular\ChangeSet::create('mychanges')
6dc348de
TO
2294 * ->alterHtml('~/crmMailing/EditMailingCtrl/2step.html', function(phpQueryObject $doc) {
2295 * $doc->find('[ng-form="crmMailingSubform"]')->attr('cat-stevens', 'ts(\'wild world\')');
2296 * })
2297 * );
36bd3f7f 2298 * $angular->add($changeSet);
6dc348de
TO
2299 * }
2300 * @endCode
2301 */
2302 public static function alterAngular($angular) {
be2fb01f 2303 $event = \Civi\Core\Event\GenericHookEvent::create([
6dc348de 2304 'angular' => $angular,
be2fb01f 2305 ]);
6dc348de
TO
2306 Civi::dispatcher()->dispatch('hook_civicrm_alterAngular', $event);
2307 }
2308
c4560ed2
CW
2309 /**
2310 * This hook is called when building a link to a semi-static asset.
2311 *
2312 * @param string $asset
2313 * The name of the asset.
2314 * Ex: 'angular.json'
2315 * @param array $params
2316 * List of optional arguments which influence the content.
2317 * @return null
2318 * the return value is ignored
2319 */
2320 public static function getAssetUrl(&$asset, &$params) {
2321 return self::singleton()->invoke(['asset', 'params'],
2322 $asset, $params, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
2323 'civicrm_getAssetUrl'
2324 );
2325 }
2326
87e3fe24
TO
2327 /**
2328 * This hook is called whenever the system builds a new copy of
2329 * semi-static asset.
2330 *
2331 * @param string $asset
2332 * The name of the asset.
2333 * Ex: 'angular.json'
2334 * @param array $params
2335 * List of optional arguments which influence the content.
2336 * Note: Params are immutable because they are part of the cache-key.
2337 * @param string $mimeType
2338 * Initially, NULL. Modify to specify the mime-type.
2339 * @param string $content
2340 * Initially, NULL. Modify to specify the rendered content.
2341 * @return null
2342 * the return value is ignored
2343 */
2344 public static function buildAsset($asset, $params, &$mimeType, &$content) {
be2fb01f 2345 return self::singleton()->invoke(['asset', 'params', 'mimeType', 'content'],
87e3fe24
TO
2346 $asset, $params, $mimeType, $content, self::$_nullObject, self::$_nullObject,
2347 'civicrm_buildAsset'
2348 );
2349 }
2350
708d8fa2
TO
2351 /**
2352 * This hook fires whenever a record in a case changes.
2353 *
2354 * @param \Civi\CCase\Analyzer $analyzer
542441f4 2355 * A bundle of data about the case (such as the case and activity records).
708d8fa2 2356 */
00be9182 2357 public static function caseChange(\Civi\CCase\Analyzer $analyzer) {
708d8fa2 2358 $event = new \Civi\CCase\Event\CaseChangeEvent($analyzer);
c73e3098 2359 \Civi::dispatcher()->dispatch('hook_civicrm_caseChange', $event);
708d8fa2 2360 }
688ad538
TO
2361
2362 /**
fe482240 2363 * Generate a default CRUD URL for an entity.
688ad538 2364 *
77855840
TO
2365 * @param array $spec
2366 * With keys:.
688ad538
TO
2367 * - action: int, eg CRM_Core_Action::VIEW or CRM_Core_Action::UPDATE
2368 * - entity_table: string
2369 * - entity_id: int
2370 * @param CRM_Core_DAO $bao
77855840
TO
2371 * @param array $link
2372 * To define the link, add these keys to $link:.
16b10e64
CW
2373 * - title: string
2374 * - path: string
2375 * - query: array
2376 * - url: string (used in lieu of "path"/"query")
688ad538
TO
2377 * Note: if making "url" CRM_Utils_System::url(), set $htmlize=false
2378 * @return mixed
2379 */
00be9182 2380 public static function crudLink($spec, $bao, &$link) {
be2fb01f 2381 return self::singleton()->invoke(['spec', 'bao', 'link'], $spec, $bao, $link,
688ad538
TO
2382 self::$_nullObject, self::$_nullObject, self::$_nullObject,
2383 'civicrm_crudLink'
2384 );
2385 }
6cccc6d4 2386
40787e18
TO
2387 /**
2388 * Modify the CiviCRM container - add new services, parameters, extensions, etc.
2389 *
2390 * @code
2391 * use Symfony\Component\Config\Resource\FileResource;
2392 * use Symfony\Component\DependencyInjection\Definition;
2393 *
2394 * function mymodule_civicrm_container($container) {
2395 * $container->addResource(new FileResource(__FILE__));
2396 * $container->setDefinition('mysvc', new Definition('My\Class', array()));
2397 * }
2398 * @endcode
2399 *
2400 * Tip: The container configuration will be compiled/cached. The default cache
2401 * behavior is aggressive. When you first implement the hook, be sure to
2402 * flush the cache. Additionally, you should relax caching during development.
2403 * In `civicrm.settings.php`, set define('CIVICRM_CONTAINER_CACHE', 'auto').
2404 *
4d8e83b6
TO
2405 * Note: This is a preboot hook. It will dispatch via the extension/module
2406 * subsystem but *not* the Symfony EventDispatcher.
2407 *
40787e18
TO
2408 * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
2409 * @see http://symfony.com/doc/current/components/dependency_injection/index.html
2410 */
2411 public static function container(\Symfony\Component\DependencyInjection\ContainerBuilder $container) {
be2fb01f 2412 self::singleton()->invoke(['container'], $container, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_container');
40787e18
TO
2413 }
2414
6cccc6d4 2415 /**
6714d8d2 2416 * @param array $fileSearches CRM_Core_FileSearchInterface
6cccc6d4
TO
2417 * @return mixed
2418 */
00be9182 2419 public static function fileSearches(&$fileSearches) {
be2fb01f 2420 return self::singleton()->invoke(['fileSearches'], $fileSearches,
6cccc6d4
TO
2421 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
2422 'civicrm_fileSearches'
2423 );
2424 }
96025800 2425
260e353b
TO
2426 /**
2427 * Check system status.
2428 *
2429 * @param array $messages
2430 * Array<CRM_Utils_Check_Message>. A list of messages regarding system status.
2431 * @return mixed
2432 */
2433 public static function check(&$messages) {
2434 return self::singleton()
be2fb01f 2435 ->invoke(['messages'], $messages, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_check');
260e353b
TO
2436 }
2437
75c8a3f7
GC
2438 /**
2439 * This hook is called when a query string of the CSV Batch export is generated.
54957108 2440 *
2441 * @param string $query
2442 *
2443 * @return mixed
75c8a3f7
GC
2444 */
2445 public static function batchQuery(&$query) {
be2fb01f 2446 return self::singleton()->invoke(['query'], $query, self::$_nullObject,
75c8a3f7
GC
2447 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
2448 'civicrm_batchQuery'
2449 );
2450 }
2451
7340e501
PN
2452 /**
2453 * This hook is called to alter Deferred revenue item values just before they are
2454 * inserted in civicrm_financial_trxn table
2455 *
2456 * @param array $deferredRevenues
2457 *
7f35de6b
PN
2458 * @param array $contributionDetails
2459 *
2460 * @param bool $update
2461 *
2462 * @param string $context
2463 *
7340e501
PN
2464 * @return mixed
2465 */
7f35de6b 2466 public static function alterDeferredRevenueItems(&$deferredRevenues, $contributionDetails, $update, $context) {
be2fb01f 2467 return self::singleton()->invoke(['deferredRevenues', 'contributionDetails', 'update', 'context'], $deferredRevenues, $contributionDetails, $update, $context,
7f35de6b 2468 self::$_nullObject, self::$_nullObject, 'civicrm_alterDeferredRevenueItems'
7340e501
PN
2469 );
2470 }
2471
75c8a3f7
GC
2472 /**
2473 * This hook is called when the entries of the CSV Batch export are mapped.
54957108 2474 *
2475 * @param array $results
2476 * @param array $items
2477 *
2478 * @return mixed
75c8a3f7
GC
2479 */
2480 public static function batchItems(&$results, &$items) {
be2fb01f 2481 return self::singleton()->invoke(['results', 'items'], $results, $items,
75c8a3f7
GC
2482 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
2483 'civicrm_batchItems'
2484 );
2485 }
2486
72e86d7d
CW
2487 /**
2488 * This hook is called when core resources are being loaded
2489 *
2490 * @see CRM_Core_Resources::coreResourceList
2491 *
2492 * @param array $list
e3c1e85b 2493 * @param string $region
72e86d7d 2494 */
e3c1e85b 2495 public static function coreResourceList(&$list, $region) {
be2fb01f 2496 self::singleton()->invoke(['list', 'region'], $list, $region,
e3c1e85b 2497 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
72e86d7d
CW
2498 'civicrm_coreResourceList'
2499 );
2500 }
2501
fd7c068f
CW
2502 /**
2503 * Allows the list of filters on the EntityRef widget to be altered.
2504 *
2505 * @see CRM_Core_Resources::entityRefFilters
2506 *
2507 * @param array $filters
7022db93 2508 * @param array $links
fd7c068f 2509 */
77d0bf4e
PN
2510 public static function entityRefFilters(&$filters, &$links = NULL) {
2511 self::singleton()->invoke(['filters', 'links'], $filters, $links, self::$_nullObject,
fd7c068f
CW
2512 self::$_nullObject, self::$_nullObject, self::$_nullObject,
2513 'civicrm_entityRefFilters'
2514 );
2515 }
2516
aa00da9b 2517 /**
f3f00653 2518 * This hook is called for bypass a few civicrm urls from IDS check.
2519 *
2520 * @param array $skip list of civicrm urls
2521 *
2522 * @return mixed
aa00da9b 2523 */
2524 public static function idsException(&$skip) {
be2fb01f 2525 return self::singleton()->invoke(['skip'], $skip, self::$_nullObject,
aa00da9b 2526 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
2527 'civicrm_idsException'
2528 );
2529 }
2530
e6209c6e
J
2531 /**
2532 * This hook is called when a geocoder's format method is called.
2533 *
4b62bfd8 2534 * @param string $geoProvider
e6209c6e
J
2535 * @param array $values
2536 * @param SimpleXMLElement $xml
f3f00653 2537 *
2538 * @return mixed
e6209c6e 2539 */
4b62bfd8 2540 public static function geocoderFormat($geoProvider, &$values, $xml) {
be2fb01f 2541 return self::singleton()->invoke(['geoProvider', 'values', 'xml'], $geoProvider, $values, $xml,
4b62bfd8 2542 self::$_nullObject, self::$_nullObject, self::$_nullObject,
e6209c6e
J
2543 'civicrm_geocoderFormat'
2544 );
2545 }
2546
0613768a
EE
2547 /**
2548 * This hook is called before an inbound SMS is processed.
2549 *
e97c66ff 2550 * @param \CRM_SMS_Message $message
6714d8d2 2551 * An SMS message received
caed3ddc
SL
2552 * @return mixed
2553 */
2554 public static function inboundSMS(&$message) {
be2fb01f 2555 return self::singleton()->invoke(['message'], $message, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_inboundSMS');
0613768a
EE
2556 }
2557
33f07374 2558 /**
2559 * This hook is called to modify api params of EntityRef form field
2560 *
2561 * @param array $params
6714d8d2 2562 * @param string $formName
33f07374 2563 * @return mixed
2564 */
f9585de5 2565 public static function alterEntityRefParams(&$params, $formName) {
be2fb01f 2566 return self::singleton()->invoke(['params', 'formName'], $params, $formName,
33f07374 2567 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
2568 'civicrm_alterEntityRefParams'
2569 );
2570 }
2571
912d0751
RT
2572 /**
2573 * This hook is called before a scheduled job is executed
2574 *
2575 * @param CRM_Core_DAO_Job $job
2576 * The job to be executed
2577 * @param array $params
2578 * The arguments to be given to the job
2579 */
2580 public static function preJob($job, $params) {
be2fb01f 2581 return self::singleton()->invoke(['job', 'params'], $job, $params,
912d0751
RT
2582 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
2583 'civicrm_preJob'
2584 );
2585 }
2586
2587 /**
2588 * This hook is called after a scheduled job is executed
2589 *
2590 * @param CRM_Core_DAO_Job $job
2591 * The job that was executed
2592 * @param array $params
2593 * The arguments given to the job
2594 * @param array $result
2595 * The result of the API call, or the thrown exception if any
2596 */
2597 public static function postJob($job, $params, $result) {
be2fb01f 2598 return self::singleton()->invoke(['job', 'params', 'result'], $job, $params, $result,
912d0751
RT
2599 self::$_nullObject, self::$_nullObject, self::$_nullObject,
2600 'civicrm_postJob'
2601 );
2602 }
2603
3417627c 2604 /**
2605 * This hook is called before and after constructing mail recipients.
2606 * Allows user to alter filter and/or search query to fetch mail recipients
2607 *
2608 * @param CRM_Mailing_DAO_Mailing $mailingObject
906298d3
TO
2609 * @param array $criteria
2610 * A list of SQL criteria; you can add/remove/replace/modify criteria.
2611 * Array(string $name => CRM_Utils_SQL_Select $criterion).
2612 * Ex: array('do_not_email' => CRM_Utils_SQL_Select::fragment()->where("$contact.do_not_email = 0")).
3417627c 2613 * @param string $context
906298d3
TO
2614 * Ex: 'pre', 'post'
2615 * @return mixed
3417627c 2616 */
906298d3 2617 public static function alterMailingRecipients(&$mailingObject, &$criteria, $context) {
be2fb01f 2618 return self::singleton()->invoke(['mailingObject', 'params', 'context'],
906298d3 2619 $mailingObject, $criteria, $context,
737f12a7 2620 self::$_nullObject, self::$_nullObject, self::$_nullObject,
3417627c 2621 'civicrm_alterMailingRecipients'
2622 );
2623 }
2624
2d39b9c0
SL
2625 /**
2626 * ALlow Extensions to custom process IPN hook data such as sending Google Analyitcs information based on the IPN
2627 * @param array $IPNData - Array of IPN Data
2628 * @return mixed
2629 */
2630 public static function postIPNProcess(&$IPNData) {
be2fb01f 2631 return self::singleton()->invoke(['IPNData'],
2d39b9c0
SL
2632 $IPNData, self::$_nullObject, self::$_nullObject,
2633 self::$_nullObject, self::$_nullObject, self::$_nullObject,
2634 'civicrm_postIPNProcess'
2635 );
2636 }
2637
9fdf2f17
SL
2638 /**
2639 * Allow extensions to modify the array of acceptable fields to be included on profiles
2640 * @param array $fields
92f06cdd 2641 * format is [Entity => array of DAO fields]
9fdf2f17
SL
2642 * @return mixed
2643 */
2644 public static function alterUFFields(&$fields) {
2645 return self::singleton()->invoke(['fields'],
2646 $fields, self::$_nullObject, self::$_nullObject,
2647 self::$_nullObject, self::$_nullObject, self::$_nullObject,
2648 'civicrm_alterUFFields'
2649 );
2650 }
2651
6a488035 2652}