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