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