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