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