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