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