Merge pull request #14557 from civicrm/5.15
[civicrm-core.git] / CRM / Utils / Hook.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CiviCRM_Hook
31 * @copyright CiviCRM LLC (c) 2004-2019
32 */
33 abstract class CRM_Utils_Hook {
34
35 // Allowed values for dashboard hook content placement
36 // Default - place content below activity list
37 const DASHBOARD_BELOW = 1;
38 // Place content above activity list
39 const DASHBOARD_ABOVE = 2;
40 // Don't display activity list at all
41 const DASHBOARD_REPLACE = 3;
42
43 // by default - place content below existing content
44 const SUMMARY_BELOW = 1;
45 // place hook content above
46 const SUMMARY_ABOVE = 2;
47 /**
48 *create your own summaries
49 */
50 const SUMMARY_REPLACE = 3;
51
52 /**
53 * 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 * A theme is a set of CSS files which are loaded on CiviCRM pages. To register a new
607 * theme, add it to the $themes array. Use these properties:
608 *
609 * - ext: string (required)
610 * The full name of the extension which defines the theme.
611 * Ex: "org.civicrm.themes.greenwich".
612 * - title: string (required)
613 * Visible title.
614 * - help: string (optional)
615 * Description of the theme's appearance.
616 * - url_callback: mixed (optional)
617 * A function ($themes, $themeKey, $cssExt, $cssFile) which returns the URL(s) for a CSS resource.
618 * Returns either an array of URLs or PASSTHRU.
619 * Ex: \Civi\Core\Themes\Resolvers::simple (default)
620 * Ex: \Civi\Core\Themes\Resolvers::none
621 * - prefix: string (optional)
622 * A prefix within the extension folder to prepend to the file name.
623 * - search_order: array (optional)
624 * A list of themes to search.
625 * Generally, the last theme should be "*fallback*" (Civi\Core\Themes::FALLBACK).
626 * - excludes: array (optional)
627 * A list of files (eg "civicrm:css/bootstrap.css" or "$ext:$file") which should never
628 * be returned (they are excluded from display).
629 *
630 * @param array $themes
631 * List of themes, keyed by name.
632 * @return null
633 * the return value is ignored
634 */
635 public static function themes(&$themes) {
636 return self::singleton()->invoke(1, $themes,
637 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
638 'civicrm_themes'
639 );
640 }
641
642 /**
643 * The activeTheme hook determines which theme is active.
644 *
645 * @param string $theme
646 * The identifier for the theme. Alterable.
647 * Ex: 'greenwich'.
648 * @param array $context
649 * Information about the current page-request. Includes some mix of:
650 * - page: the relative path of the current Civi page (Ex: 'civicrm/dashboard').
651 * - themes: an instance of the Civi\Core\Themes service.
652 * @return null
653 * the return value is ignored
654 */
655 public static function activeTheme(&$theme, $context) {
656 return self::singleton()->invoke(array('theme', 'context'), $theme, $context,
657 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
658 'civicrm_activeTheme'
659 );
660 }
661
662 /**
663 * This hook is called for declaring managed entities via API.
664 *
665 * @param array $entities
666 * List of pending entities. Each entity is an array with keys:
667 * + '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")
668 * + 'name': string, a symbolic name which can be used to track this entity (Note: Each module creates its own namespace)
669 * + 'entity': string, an entity-type supported by the CiviCRM API (Note: this currently must be an entity which supports the 'is_active' property)
670 * + 'params': array, the entity data as supported by the CiviCRM API
671 * + 'update' (v4.5+): string, a policy which describes when to update records
672 * - 'always' (default): always update the managed-entity record; changes in $entities will override any local changes (eg by the site-admin)
673 * - 'never': never update the managed-entity record; changes made locally (eg by the site-admin) will override changes in $entities
674 * + '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)
675 * - 'always' (default): always delete orphaned records
676 * - 'never': never delete orphaned records
677 * - '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.)
678 *
679 * @return null
680 * the return value is ignored
681 */
682 public static function managed(&$entities) {
683 return self::singleton()->invoke(['entities'], $entities,
684 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
685 'civicrm_managed'
686 );
687 }
688
689 /**
690 * This hook is called when rendering the dashboard (q=civicrm/dashboard)
691 *
692 * @param int $contactID
693 * The contactID for whom the dashboard is being rendered.
694 * @param int $contentPlacement
695 * (output parameter) where should the hook content be displayed.
696 * relative to the activity list
697 *
698 * @return string
699 * the html snippet to include in the dashboard
700 */
701 public static function dashboard($contactID, &$contentPlacement = self::DASHBOARD_BELOW) {
702 $retval = self::singleton()->invoke(['contactID', 'contentPlacement'], $contactID, $contentPlacement,
703 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
704 'civicrm_dashboard'
705 );
706
707 /*
708 * Note we need this seemingly unnecessary code because in the event that the implementation
709 * of the hook declares the second parameter but doesn't set it, then it comes back unset even
710 * though we have a default value in this function's declaration above.
711 */
712 if (!isset($contentPlacement)) {
713 $contentPlacement = self::DASHBOARD_BELOW;
714 }
715
716 return $retval;
717 }
718
719 /**
720 * This hook is called before storing recently viewed items.
721 *
722 * @param array $recentArray
723 * An array of recently viewed or processed items, for in place modification.
724 *
725 * @return array
726 */
727 public static function recent(&$recentArray) {
728 return self::singleton()->invoke(['recentArray'], $recentArray,
729 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
730 'civicrm_recent'
731 );
732 }
733
734 /**
735 * Determine how many other records refer to a given record.
736 *
737 * @param CRM_Core_DAO $dao
738 * The item for which we want a reference count.
739 * @param array $refCounts
740 * Each item in the array is an Array with keys:
741 * - name: string, eg "sql:civicrm_email:contact_id"
742 * - type: string, eg "sql"
743 * - count: int, eg "5" if there are 5 email addresses that refer to $dao
744 *
745 * @return mixed
746 * Return is not really intended to be used.
747 */
748 public static function referenceCounts($dao, &$refCounts) {
749 return self::singleton()->invoke(['dao', 'refCounts'], $dao, $refCounts,
750 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
751 'civicrm_referenceCounts'
752 );
753 }
754
755 /**
756 * This hook is called when building the amount structure for a Contribution or Event Page.
757 *
758 * @param int $pageType
759 * Is this a contribution or event page.
760 * @param CRM_Core_Form $form
761 * Reference to the form object.
762 * @param array $amount
763 * The amount structure to be displayed.
764 *
765 * @return null
766 */
767 public static function buildAmount($pageType, &$form, &$amount) {
768 return self::singleton()->invoke(['pageType', 'form', 'amount'], $pageType, $form, $amount, self::$_nullObject,
769 self::$_nullObject, self::$_nullObject, 'civicrm_buildAmount');
770 }
771
772 /**
773 * This hook is called when building the state list for a particular country.
774 *
775 * @param array $countryID
776 * The country id whose states are being selected.
777 * @param $states
778 *
779 * @return null
780 */
781 public static function buildStateProvinceForCountry($countryID, &$states) {
782 return self::singleton()->invoke(['countryID', 'states'], $countryID, $states,
783 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
784 'civicrm_buildStateProvinceForCountry'
785 );
786 }
787
788 /**
789 * This hook is called when rendering the tabs for a contact (q=civicrm/contact/view)c
790 *
791 * @param array $tabs
792 * The array of tabs that will be displayed.
793 * @param int $contactID
794 * The contactID for whom the dashboard is being rendered.
795 *
796 * @return null
797 * @deprecated Use tabset() instead.
798 */
799 public static function tabs(&$tabs, $contactID) {
800 return self::singleton()->invoke(['tabs', 'contactID'], $tabs, $contactID,
801 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_tabs'
802 );
803 }
804
805 /**
806 * This hook is called when rendering the tabs used for events and potentially
807 * contribution pages, etc.
808 *
809 * @param string $tabsetName
810 * Name of the screen or visual element.
811 * @param array $tabs
812 * Tabs that will be displayed.
813 * @param array $context
814 * Extra data about the screen or context in which the tab is used.
815 *
816 * @return null
817 */
818 public static function tabset($tabsetName, &$tabs, $context) {
819 return self::singleton()->invoke(['tabsetName', 'tabs', 'context'], $tabsetName, $tabs,
820 $context, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_tabset'
821 );
822 }
823
824 /**
825 * This hook is called when sending an email / printing labels
826 *
827 * @param array $tokens
828 * The list of tokens that can be used for the contact.
829 *
830 * @return null
831 */
832 public static function tokens(&$tokens) {
833 return self::singleton()->invoke(['tokens'], $tokens,
834 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_tokens'
835 );
836 }
837
838 /**
839 * This hook is called when sending an email / printing labels to get the values for all the
840 * tokens returned by the 'tokens' hook
841 *
842 * @param array $details
843 * The array to store the token values indexed by contactIDs (unless it a single).
844 * @param array $contactIDs
845 * An array of contactIDs.
846 * @param int $jobID
847 * The jobID if this is associated with a CiviMail mailing.
848 * @param array $tokens
849 * The list of tokens associated with the content.
850 * @param string $className
851 * The top level className from where the hook is invoked.
852 *
853 * @return null
854 */
855 public static function tokenValues(
856 &$details,
857 $contactIDs,
858 $jobID = NULL,
859 $tokens = [],
860 $className = NULL
861 ) {
862 return self::singleton()
863 ->invoke(['details', 'contactIDs', 'jobID', 'tokens', 'className'], $details, $contactIDs, $jobID, $tokens, $className, self::$_nullObject, 'civicrm_tokenValues');
864 }
865
866 /**
867 * This hook is called before a CiviCRM Page is rendered. You can use this hook to insert smarty variables
868 * in a template
869 *
870 * @param object $page
871 * The page that will be rendered.
872 *
873 * @return null
874 */
875 public static function pageRun(&$page) {
876 return self::singleton()->invoke(['page'], $page,
877 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
878 'civicrm_pageRun'
879 );
880 }
881
882 /**
883 * This hook is called after a copy of an object has been made. The current objects are
884 * Event, Contribution Page and UFGroup
885 *
886 * @param string $objectName
887 * Name of the object.
888 * @param object $object
889 * Reference to the copy.
890 *
891 * @return null
892 */
893 public static function copy($objectName, &$object) {
894 return self::singleton()->invoke(['objectName', 'object'], $objectName, $object,
895 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
896 'civicrm_copy'
897 );
898 }
899
900 /**
901 * This hook is called when a contact unsubscribes from a mailing. It allows modules
902 * to override what the contacts are removed from.
903 *
904 * @param string $op
905 * Ignored for now
906 * @param int $mailingId
907 * The id of the mailing to unsub from
908 * @param int $contactId
909 * The id of the contact who is unsubscribing
910 * @param array|int $groups
911 * Groups the contact will be removed from.
912 * @param array|int $baseGroups
913 * Base groups (used in smart mailings) the contact will be removed from.
914 *
915 *
916 * @return mixed
917 */
918 public static function unsubscribeGroups($op, $mailingId, $contactId, &$groups, &$baseGroups) {
919 return self::singleton()
920 ->invoke(['op', 'mailingId', 'contactId', 'groups', 'baseGroups'], $op, $mailingId, $contactId, $groups, $baseGroups, self::$_nullObject, 'civicrm_unsubscribeGroups');
921 }
922
923 /**
924 * This hook is called when CiviCRM needs to edit/display a custom field with options
925 *
926 * @deprecated in favor of hook_civicrm_fieldOptions
927 *
928 * @param int $customFieldID
929 * The custom field ID.
930 * @param array $options
931 * The current set of options for that custom field.
932 * You can add/remove existing options.
933 * Important: This array may contain meta-data about the field that is needed elsewhere, so it is important
934 * to be careful to not overwrite the array.
935 * Only add/edit/remove the specific field options you intend to affect.
936 * @param bool $detailedFormat
937 * If true, the options are in an ID => array ( 'id' => ID, 'label' => label, 'value' => value ) format
938 * @param array $selectAttributes
939 * Contain select attribute(s) if any.
940 *
941 * @return mixed
942 */
943 public static function customFieldOptions($customFieldID, &$options, $detailedFormat = FALSE, $selectAttributes = []) {
944 // Weird: $selectAttributes is inputted but not outputted.
945 return self::singleton()->invoke(['customFieldID', 'options', 'detailedFormat'], $customFieldID, $options, $detailedFormat,
946 self::$_nullObject, self::$_nullObject, self::$_nullObject,
947 'civicrm_customFieldOptions'
948 );
949 }
950
951 /**
952 * Hook for modifying field options
953 *
954 * @param string $entity
955 * @param string $field
956 * @param array $options
957 * @param array $params
958 *
959 * @return mixed
960 */
961 public static function fieldOptions($entity, $field, &$options, $params) {
962 return self::singleton()->invoke(['entity', 'field', 'options', 'params'], $entity, $field, $options, $params,
963 self::$_nullObject, self::$_nullObject,
964 'civicrm_fieldOptions'
965 );
966 }
967
968 /**
969 *
970 * This hook is called to display the list of actions allowed after doing a search.
971 * This allows the module developer to inject additional actions or to remove existing actions.
972 *
973 * @param string $objectType
974 * The object type for this search.
975 * - activity, campaign, case, contact, contribution, event, grant, membership, and pledge are supported.
976 * @param array $tasks
977 * The current set of tasks for that custom field.
978 * You can add/remove existing tasks.
979 * Each task needs to have a title (eg 'title' => ts( 'Group - add contacts')) and a class
980 * (eg 'class' => 'CRM_Contact_Form_Task_AddToGroup').
981 * Optional result (boolean) may also be provided. Class can be an array of classes (not sure what that does :( ).
982 * The key for new Task(s) should not conflict with the keys for core tasks of that $objectType, which can be
983 * found in CRM/$objectType/Task.php.
984 *
985 * @return mixed
986 */
987 public static function searchTasks($objectType, &$tasks) {
988 return self::singleton()->invoke(['objectType', 'tasks'], $objectType, $tasks,
989 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
990 'civicrm_searchTasks'
991 );
992 }
993
994 /**
995 * @param mixed $form
996 * @param array $params
997 *
998 * @return mixed
999 */
1000 public static function eventDiscount(&$form, &$params) {
1001 return self::singleton()->invoke(['form', 'params'], $form, $params,
1002 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
1003 'civicrm_eventDiscount'
1004 );
1005 }
1006
1007 /**
1008 * This hook is called when composing a mailing. You can include / exclude other groups as needed.
1009 *
1010 * @param mixed $form
1011 * The form object for which groups / mailings being displayed
1012 * @param array $groups
1013 * The list of groups being included / excluded
1014 * @param array $mailings
1015 * The list of mailings being included / excluded
1016 *
1017 * @return mixed
1018 */
1019 public static function mailingGroups(&$form, &$groups, &$mailings) {
1020 return self::singleton()->invoke(['form', 'groups', 'mailings'], $form, $groups, $mailings,
1021 self::$_nullObject, self::$_nullObject, self::$_nullObject,
1022 'civicrm_mailingGroups'
1023 );
1024 }
1025
1026 /**
1027 * (Experimental) Modify the list of template-types used for CiviMail composition.
1028 *
1029 * @param array $types
1030 * Sequentially indexed list of template types. Each type specifies:
1031 * - name: string
1032 * - editorUrl: string, Angular template URL
1033 * - weight: int, priority when picking a default value for new mailings
1034 * @return mixed
1035 */
1036 public static function mailingTemplateTypes(&$types) {
1037 return self::singleton()->invoke(['types'], $types, self::$_nullObject, self::$_nullObject,
1038 self::$_nullObject, self::$_nullObject, self::$_nullObject,
1039 'civicrm_mailingTemplateTypes'
1040 );
1041 }
1042
1043 /**
1044 * This hook is called when composing the array of membershipTypes and their cost during a membership registration
1045 * (new or renewal).
1046 * Note the hook is called on initial page load and also reloaded after submit (PRG pattern).
1047 * You can use it to alter the membership types when first loaded, or after submission
1048 * (for example if you want to gather data in the form and use it to alter the fees).
1049 *
1050 * @param mixed $form
1051 * The form object that is presenting the page
1052 * @param array $membershipTypes
1053 * The array of membership types and their amount
1054 *
1055 * @return mixed
1056 */
1057 public static function membershipTypeValues(&$form, &$membershipTypes) {
1058 return self::singleton()->invoke(['form', 'membershipTypes'], $form, $membershipTypes,
1059 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
1060 'civicrm_membershipTypeValues'
1061 );
1062 }
1063
1064 /**
1065 * This hook is called when rendering the contact summary.
1066 *
1067 * @param int $contactID
1068 * The contactID for whom the summary is being rendered
1069 * @param mixed $content
1070 * @param int $contentPlacement
1071 * Specifies where the hook content should be displayed relative to the
1072 * existing content
1073 *
1074 * @return string
1075 * The html snippet to include in the contact summary
1076 */
1077 public static function summary($contactID, &$content, &$contentPlacement = self::SUMMARY_BELOW) {
1078 return self::singleton()->invoke(['contactID', 'content', 'contentPlacement'], $contactID, $content, $contentPlacement,
1079 self::$_nullObject, self::$_nullObject, self::$_nullObject,
1080 'civicrm_summary'
1081 );
1082 }
1083
1084 /**
1085 * Use this hook to populate the list of contacts returned by Contact Reference custom fields.
1086 * By default, Contact Reference fields will search on and return all CiviCRM contacts.
1087 * If you want to limit the contacts returned to a specific group, or some other criteria
1088 * - you can override that behavior by providing a SQL query that returns some subset of your contacts.
1089 * The hook is called when the query is executed to get the list of contacts to display.
1090 *
1091 * @param mixed $query
1092 * - the query that will be executed (input and output parameter);.
1093 * It's important to realize that the ACL clause is built prior to this hook being fired,
1094 * so your query will ignore any ACL rules that may be defined.
1095 * Your query must return two columns:
1096 * the contact 'data' to display in the autocomplete dropdown (usually contact.sort_name - aliased as 'data')
1097 * the contact IDs
1098 * @param string $queryText
1099 * The name string to execute the query against (this is the value being typed in by the user).
1100 * @param string $context
1101 * The context in which this ajax call is being made (for example: 'customfield', 'caseview').
1102 * @param int $id
1103 * The id of the object for which the call is being made.
1104 * For custom fields, it will be the custom field id
1105 *
1106 * @return mixed
1107 */
1108 public static function contactListQuery(&$query, $queryText, $context, $id) {
1109 return self::singleton()->invoke(['query', 'queryText', 'context', 'id'], $query, $queryText, $context, $id,
1110 self::$_nullObject, self::$_nullObject,
1111 'civicrm_contactListQuery'
1112 );
1113 }
1114
1115 /**
1116 * Hook definition for altering payment parameters before talking to a payment processor back end.
1117 *
1118 * Definition will look like this:
1119 *
1120 * function hook_civicrm_alterPaymentProcessorParams(
1121 * $paymentObj,
1122 * &$rawParams,
1123 * &$cookedParams
1124 * );
1125 *
1126 * @param CRM_Core_Payment $paymentObj
1127 * Instance of payment class of the payment processor invoked (e.g., 'CRM_Core_Payment_Dummy')
1128 * See discussion in CRM-16224 as to whether $paymentObj should be passed by reference.
1129 * @param array &$rawParams
1130 * array of params as passed to to the processor
1131 * @param array &$cookedParams
1132 * params after the processor code has translated them into its own key/value pairs
1133 *
1134 * @return mixed
1135 * This return is not really intended to be used.
1136 */
1137 public static function alterPaymentProcessorParams(
1138 $paymentObj,
1139 &$rawParams,
1140 &$cookedParams
1141 ) {
1142 return self::singleton()->invoke(['paymentObj', 'rawParams', 'cookedParams'], $paymentObj, $rawParams, $cookedParams,
1143 self::$_nullObject, self::$_nullObject, self::$_nullObject,
1144 'civicrm_alterPaymentProcessorParams'
1145 );
1146 }
1147
1148 /**
1149 * This hook is called when an email is about to be sent by CiviCRM.
1150 *
1151 * @param array $params
1152 * Array fields include: groupName, from, toName, toEmail, subject, cc, bcc, text, html,
1153 * returnPath, replyTo, headers, attachments (array)
1154 * @param string $context
1155 * The context in which the hook is being invoked, eg 'civimail'.
1156 *
1157 * @return mixed
1158 */
1159 public static function alterMailParams(&$params, $context = NULL) {
1160 return self::singleton()->invoke(['params', 'context'], $params, $context,
1161 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
1162 'civicrm_alterMailParams'
1163 );
1164 }
1165
1166 /**
1167 * This hook is called when membership status is being calculated.
1168 *
1169 * @param array $membershipStatus
1170 * Membership status details as determined - alter if required.
1171 * @param array $arguments
1172 * Arguments passed in to calculate date.
1173 * - 'start_date'
1174 * - 'end_date'
1175 * - 'status_date'
1176 * - 'join_date'
1177 * - 'exclude_is_admin'
1178 * - 'membership_type_id'
1179 * @param array $membership
1180 * Membership details from the calling function.
1181 *
1182 * @return mixed
1183 */
1184 public static function alterCalculatedMembershipStatus(&$membershipStatus, $arguments, $membership) {
1185 return self::singleton()->invoke(['membershipStatus', 'arguments', 'membership'], $membershipStatus, $arguments,
1186 $membership, self::$_nullObject, self::$_nullObject, self::$_nullObject,
1187 'civicrm_alterCalculatedMembershipStatus'
1188 );
1189 }
1190
1191 /**
1192 * This hook is called after getting the content of the mail and before tokenizing it.
1193 *
1194 * @param array $content
1195 * Array fields include: html, text, subject
1196 *
1197 * @return mixed
1198 */
1199 public static function alterMailContent(&$content) {
1200 return self::singleton()->invoke(['content'], $content,
1201 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
1202 'civicrm_alterMailContent'
1203 );
1204 }
1205
1206 /**
1207 * This hook is called when rendering the Manage Case screen.
1208 *
1209 * @param int $caseID
1210 * The case ID.
1211 *
1212 * @return array
1213 * Array of data to be displayed, where the key is a unique id to be used for styling (div id's)
1214 * and the value is an array with keys 'label' and 'value' specifying label/value pairs
1215 */
1216 public static function caseSummary($caseID) {
1217 return self::singleton()->invoke(['caseID'], $caseID,
1218 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
1219 'civicrm_caseSummary'
1220 );
1221 }
1222
1223 /**
1224 * This hook is called when locating CiviCase types.
1225 *
1226 * @param array $caseTypes
1227 *
1228 * @return mixed
1229 */
1230 public static function caseTypes(&$caseTypes) {
1231 return self::singleton()
1232 ->invoke(['caseTypes'], $caseTypes, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_caseTypes');
1233 }
1234
1235 /**
1236 * This hook is called soon after the CRM_Core_Config object has ben initialized.
1237 * You can use this hook to modify the config object and hence behavior of CiviCRM dynamically.
1238 *
1239 * @param CRM_Core_Config|array $config
1240 * The config object
1241 *
1242 * @return mixed
1243 */
1244 public static function config(&$config) {
1245 return self::singleton()->invoke(['config'], $config,
1246 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
1247 'civicrm_config'
1248 );
1249 }
1250
1251 /**
1252 * This hooks allows to change option values.
1253 *
1254 * @deprecated in favor of hook_civicrm_fieldOptions
1255 *
1256 * @param array $options
1257 * Associated array of option values / id
1258 * @param string $groupName
1259 * Option group name
1260 *
1261 * @return mixed
1262 */
1263 public static function optionValues(&$options, $groupName) {
1264 return self::singleton()->invoke(['options', 'groupName'], $options, $groupName,
1265 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
1266 'civicrm_optionValues'
1267 );
1268 }
1269
1270 /**
1271 * This hook allows modification of the navigation menu.
1272 *
1273 * @param array $params
1274 * Associated array of navigation menu entry to Modify/Add
1275 *
1276 * @return mixed
1277 */
1278 public static function navigationMenu(&$params) {
1279 return self::singleton()->invoke(['params'], $params,
1280 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
1281 'civicrm_navigationMenu'
1282 );
1283 }
1284
1285 /**
1286 * This hook allows modification of the data used to perform merging of duplicates.
1287 *
1288 * @param string $type
1289 * The type of data being passed (cidRefs|eidRefs|relTables|sqls).
1290 * @param array $data
1291 * The data, as described in $type.
1292 * @param int $mainId
1293 * Contact_id of the contact that survives the merge.
1294 * @param int $otherId
1295 * Contact_id of the contact that will be absorbed and deleted.
1296 * @param array $tables
1297 * When $type is "sqls", an array of tables as it may have been handed to the calling function.
1298 *
1299 * @return mixed
1300 */
1301 public static function merge($type, &$data, $mainId = NULL, $otherId = NULL, $tables = NULL) {
1302 return self::singleton()->invoke(['type', 'data', 'mainId', 'otherId', 'tables'], $type, $data, $mainId, $otherId, $tables, self::$_nullObject, 'civicrm_merge');
1303 }
1304
1305 /**
1306 * This hook allows modification of the data calculated for merging locations.
1307 *
1308 * @param array $blocksDAO
1309 * Array of location DAO to be saved. These are arrays in 2 keys 'update' & 'delete'.
1310 * @param int $mainId
1311 * Contact_id of the contact that survives the merge.
1312 * @param int $otherId
1313 * Contact_id of the contact that will be absorbed and deleted.
1314 * @param array $migrationInfo
1315 * Calculated migration info, informational only.
1316 *
1317 * @return mixed
1318 */
1319 public static function alterLocationMergeData(&$blocksDAO, $mainId, $otherId, $migrationInfo) {
1320 return self::singleton()->invoke(['blocksDAO', 'mainId', 'otherId', 'migrationInfo'], $blocksDAO, $mainId, $otherId, $migrationInfo, self::$_nullObject, self::$_nullObject, 'civicrm_alterLocationMergeData');
1321 }
1322
1323 /**
1324 * This hook provides a way to override the default privacy behavior for notes.
1325 *
1326 * @param array &$noteValues
1327 * Associative array of values for this note
1328 *
1329 * @return mixed
1330 */
1331 public static function notePrivacy(&$noteValues) {
1332 return self::singleton()->invoke(['noteValues'], $noteValues,
1333 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
1334 'civicrm_notePrivacy'
1335 );
1336 }
1337
1338 /**
1339 * This hook is called before record is exported as CSV.
1340 *
1341 * @param string $exportTempTable
1342 * Name of the temporary export table used during export.
1343 * @param array $headerRows
1344 * Header rows for output.
1345 * @param array $sqlColumns
1346 * SQL columns.
1347 * @param int $exportMode
1348 * Export mode ( contact, contribution, etc...).
1349 * @param string $componentTable
1350 * Name of temporary table
1351 * @param array $ids
1352 * Array of object's ids
1353 *
1354 * @return mixed
1355 */
1356 public static function export(&$exportTempTable, &$headerRows, &$sqlColumns, &$exportMode, &$componentTable, &$ids) {
1357 return self::singleton()->invoke(['exportTempTable', 'headerRows', 'sqlColumns', 'exportMode', 'componentTable', 'ids'],
1358 $exportTempTable, $headerRows, $sqlColumns,
1359 $exportMode, $componentTable, $ids,
1360 'civicrm_export'
1361 );
1362 }
1363
1364 /**
1365 * This hook allows modification of the queries constructed from dupe rules.
1366 *
1367 * @param string $obj
1368 * Object of rulegroup class.
1369 * @param string $type
1370 * Type of queries e.g table / threshold.
1371 * @param array $query
1372 * Set of queries.
1373 *
1374 * @return mixed
1375 */
1376 public static function dupeQuery($obj, $type, &$query) {
1377 return self::singleton()->invoke(['obj', 'type', 'query'], $obj, $type, $query,
1378 self::$_nullObject, self::$_nullObject, self::$_nullObject,
1379 'civicrm_dupeQuery'
1380 );
1381 }
1382
1383 /**
1384 * Check for duplicate contacts
1385 *
1386 * @param array $dedupeParams
1387 * Array of params for finding duplicates: [
1388 * '{parameters returned by CRM_Dedupe_Finder::formatParams}
1389 * 'check_permission' => TRUE/FALSE;
1390 * 'contact_type' => $contactType;
1391 * 'rule' = $rule;
1392 * 'rule_group_id' => $ruleGroupID;
1393 * 'excludedContactIDs' => $excludedContactIDs;
1394 * @param array $dedupeResults
1395 * Array of results ['handled' => TRUE/FALSE, 'ids' => array of IDs of duplicate contacts]
1396 * @param array $contextParams
1397 * The context if relevant, eg. ['event_id' => X]
1398 *
1399 * @return mixed
1400 */
1401 public static function findDuplicates($dedupeParams, &$dedupeResults, $contextParams) {
1402 return self::singleton()
1403 ->invoke(['dedupeParams', 'dedupeResults', 'contextParams'], $dedupeParams, $dedupeResults, $contextParams, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_findDuplicates');
1404 }
1405
1406 /**
1407 * This hook is called AFTER EACH email has been processed by the script bin/EmailProcessor.php
1408 *
1409 * @param string $type
1410 * Type of mail processed: 'activity' OR 'mailing'.
1411 * @param array &$params the params that were sent to the CiviCRM API function
1412 * @param object $mail
1413 * The mail object which is an ezcMail class.
1414 * @param array &$result the result returned by the api call
1415 * @param string $action
1416 * (optional ) the requested action to be performed if the types was 'mailing'.
1417 *
1418 * @return mixed
1419 */
1420 public static function emailProcessor($type, &$params, $mail, &$result, $action = NULL) {
1421 return self::singleton()
1422 ->invoke(['type', 'params', 'mail', 'result', 'action'], $type, $params, $mail, $result, $action, self::$_nullObject, 'civicrm_emailProcessor');
1423 }
1424
1425 /**
1426 * This hook is called after a row has been processed and the
1427 * record (and associated records imported
1428 *
1429 * @param string $object
1430 * Object being imported (for now Contact only, later Contribution, Activity,.
1431 * Participant and Member)
1432 * @param string $usage
1433 * Hook usage/location (for now process only, later mapping and others).
1434 * @param string $objectRef
1435 * Import record object.
1436 * @param array $params
1437 * Array with various key values: currently.
1438 * contactID - contact id
1439 * importID - row id in temp table
1440 * importTempTable - name of tempTable
1441 * fieldHeaders - field headers
1442 * fields - import fields
1443 *
1444 * @return mixed
1445 */
1446 public static function import($object, $usage, &$objectRef, &$params) {
1447 return self::singleton()->invoke(['object', 'usage', 'objectRef', 'params'], $object, $usage, $objectRef, $params,
1448 self::$_nullObject, self::$_nullObject,
1449 'civicrm_import'
1450 );
1451 }
1452
1453 /**
1454 * This hook is called when API permissions are checked (cf. civicrm_api3_api_check_permission()
1455 * in api/v3/utils.php and _civicrm_api3_permissions() in CRM/Core/DAO/permissions.php).
1456 *
1457 * @param string $entity
1458 * The API entity (like contact).
1459 * @param string $action
1460 * The API action (like get).
1461 * @param array &$params the API parameters
1462 * @param array &$permissions the associative permissions array (probably to be altered by this hook)
1463 *
1464 * @return mixed
1465 */
1466 public static function alterAPIPermissions($entity, $action, &$params, &$permissions) {
1467 return self::singleton()->invoke(['entity', 'action', 'params', 'permissions'], $entity, $action, $params, $permissions,
1468 self::$_nullObject, self::$_nullObject,
1469 'civicrm_alterAPIPermissions'
1470 );
1471 }
1472
1473 /**
1474 * @param CRM_Core_DAO $dao
1475 *
1476 * @return mixed
1477 */
1478 public static function postSave(&$dao) {
1479 $hookName = 'civicrm_postSave_' . $dao->getTableName();
1480 return self::singleton()->invoke(['dao'], $dao,
1481 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
1482 $hookName
1483 );
1484 }
1485
1486 /**
1487 * This hook allows user to customize context menu Actions on contact summary page.
1488 *
1489 * @param array $actions
1490 * Array of all Actions in contextmenu.
1491 * @param int $contactID
1492 * ContactID for the summary page.
1493 *
1494 * @return mixed
1495 */
1496 public static function summaryActions(&$actions, $contactID = NULL) {
1497 return self::singleton()->invoke(['actions', 'contactID'], $actions, $contactID,
1498 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
1499 'civicrm_summaryActions'
1500 );
1501 }
1502
1503 /**
1504 * This hook is called from CRM_Core_Selector_Controller through which all searches in civicrm go.
1505 * This enables us hook implementors to modify both the headers and the rows
1506 *
1507 * The BIGGEST drawback with this hook is that you may need to modify the result template to include your
1508 * fields. The result files are CRM/{Contact,Contribute,Member,Event...}/Form/Selector.tpl
1509 *
1510 * However, if you use the same number of columns, you can overwrite the existing columns with the values that
1511 * you want displayed. This is a hackish, but avoids template modification.
1512 *
1513 * @param string $objectName
1514 * The component name that we are doing the search.
1515 * activity, campaign, case, contact, contribution, event, grant, membership, and pledge
1516 * @param array &$headers the list of column headers, an associative array with keys: ( name, sort, order )
1517 * @param array &$rows the list of values, an associate array with fields that are displayed for that component
1518 * @param array $selector
1519 * the selector object. Allows you access to the context of the search
1520 *
1521 * @return mixed
1522 * modify the header and values object to pass the data you need
1523 */
1524 public static function searchColumns($objectName, &$headers, &$rows, &$selector) {
1525 return self::singleton()->invoke(['objectName', 'headers', 'rows', 'selector'], $objectName, $headers, $rows, $selector,
1526 self::$_nullObject, self::$_nullObject,
1527 'civicrm_searchColumns'
1528 );
1529 }
1530
1531 /**
1532 * This hook is called when uf groups are being built for a module.
1533 *
1534 * @param string $moduleName
1535 * Module name.
1536 * @param array $ufGroups
1537 * Array of ufgroups for a module.
1538 *
1539 * @return null
1540 */
1541 public static function buildUFGroupsForModule($moduleName, &$ufGroups) {
1542 return self::singleton()->invoke(['moduleName', 'ufGroups'], $moduleName, $ufGroups,
1543 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
1544 'civicrm_buildUFGroupsForModule'
1545 );
1546 }
1547
1548 /**
1549 * This hook is called when we are determining the contactID for a specific
1550 * email address
1551 *
1552 * @param string $email
1553 * The email address.
1554 * @param int $contactID
1555 * The contactID that matches this email address, IF it exists.
1556 * @param array $result
1557 * (reference) has two fields.
1558 * contactID - the new (or same) contactID
1559 * action - 3 possible values:
1560 * CRM_Utils_Mail_Incoming::EMAILPROCESSOR_CREATE_INDIVIDUAL - create a new contact record
1561 * CRM_Utils_Mail_Incoming::EMAILPROCESSOR_OVERRIDE - use the new contactID
1562 * CRM_Utils_Mail_Incoming::EMAILPROCESSOR_IGNORE - skip this email address
1563 *
1564 * @return null
1565 */
1566 public static function emailProcessorContact($email, $contactID, &$result) {
1567 return self::singleton()->invoke(['email', 'contactID', 'result'], $email, $contactID, $result,
1568 self::$_nullObject, self::$_nullObject, self::$_nullObject,
1569 'civicrm_emailProcessorContact'
1570 );
1571 }
1572
1573 /**
1574 * Hook definition for altering the generation of Mailing Labels.
1575 *
1576 * @param array $args
1577 * An array of the args in the order defined for the tcpdf multiCell api call.
1578 * with the variable names below converted into string keys (ie $w become 'w'
1579 * as the first key for $args)
1580 * float $w Width of cells. If 0, they extend up to the right margin of the page.
1581 * float $h Cell minimum height. The cell extends automatically if needed.
1582 * string $txt String to print
1583 * mixed $border Indicates if borders must be drawn around the cell block. The value can
1584 * be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or
1585 * a string containing some or all of the following characters (in any order):
1586 * <ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul>
1587 * string $align Allows to center or align the text. Possible values are:<ul><li>L or empty string:
1588 * left align</li><li>C: center</li><li>R: right align</li><li>J: justification
1589 * (default value when $ishtml=false)</li></ul>
1590 * int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
1591 * int $ln Indicates where the current position should go after the call. Possible values are:<ul><li>0:
1592 * to the right</li><li>1: to the beginning of the next line [DEFAULT]</li><li>2: below</li></ul>
1593 * float $x x position in user units
1594 * float $y y position in user units
1595 * boolean $reseth if true reset the last cell height (default true).
1596 * int $stretch stretch character mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if
1597 * necessary</li><li>2 = forced horizontal scaling</li><li>3 = character spacing only if
1598 * necessary</li><li>4 = forced character spacing</li></ul>
1599 * boolean $ishtml set to true if $txt is HTML content (default = false).
1600 * boolean $autopadding if true, uses internal padding and automatically adjust it to account for line width.
1601 * float $maxh maximum height. It should be >= $h and less then remaining space to the bottom of the page,
1602 * or 0 for disable this feature. This feature works only when $ishtml=false.
1603 *
1604 * @return mixed
1605 */
1606 public static function alterMailingLabelParams(&$args) {
1607 return self::singleton()->invoke(['args'], $args,
1608 self::$_nullObject, self::$_nullObject,
1609 self::$_nullObject, self::$_nullObject, self::$_nullObject,
1610 'civicrm_alterMailingLabelParams'
1611 );
1612 }
1613
1614 /**
1615 * This hooks allows alteration of generated page content.
1616 *
1617 * @param $content
1618 * Previously generated content.
1619 * @param $context
1620 * Context of content - page or form.
1621 * @param $tplName
1622 * The file name of the tpl.
1623 * @param $object
1624 * A reference to the page or form object.
1625 *
1626 * @return mixed
1627 */
1628 public static function alterContent(&$content, $context, $tplName, &$object) {
1629 return self::singleton()->invoke(['content', 'context', 'tplName', 'object'], $content, $context, $tplName, $object,
1630 self::$_nullObject, self::$_nullObject,
1631 'civicrm_alterContent'
1632 );
1633 }
1634
1635 /**
1636 * This hooks allows alteration of the tpl file used to generate content. It differs from the
1637 * altercontent hook as the content has already been rendered through the tpl at that point
1638 *
1639 * @param $formName
1640 * Previously generated content.
1641 * @param $form
1642 * Reference to the form object.
1643 * @param $context
1644 * Context of content - page or form.
1645 * @param $tplName
1646 * Reference the file name of the tpl.
1647 *
1648 * @return mixed
1649 */
1650 public static function alterTemplateFile($formName, &$form, $context, &$tplName) {
1651 return self::singleton()->invoke(['formName', 'form', 'context', 'tplName'], $formName, $form, $context, $tplName,
1652 self::$_nullObject, self::$_nullObject,
1653 'civicrm_alterTemplateFile'
1654 );
1655 }
1656
1657 /**
1658 * This hook collects the trigger definition from all components.
1659 *
1660 * @param $info
1661 * @param string $tableName
1662 * (optional) the name of the table that we are interested in only.
1663 *
1664 * @internal param \reference $triggerInfo to an array of trigger information
1665 * each element has 4 fields:
1666 * table - array of tableName
1667 * when - BEFORE or AFTER
1668 * event - array of eventName - INSERT OR UPDATE OR DELETE
1669 * sql - array of statements optionally terminated with a ;
1670 * a statement can use the tokes {tableName} and {eventName}
1671 * to do token replacement with the table / event. This allows
1672 * templatizing logging and other hooks
1673 * @return mixed
1674 */
1675 public static function triggerInfo(&$info, $tableName = NULL) {
1676 return self::singleton()->invoke(['info', 'tableName'], $info, $tableName,
1677 self::$_nullObject, self::$_nullObject, self::$_nullObject,
1678 self::$_nullObject,
1679 'civicrm_triggerInfo'
1680 );
1681 }
1682
1683 /**
1684 * This hook allows changes to the spec of which tables to log.
1685 *
1686 * @param array $logTableSpec
1687 *
1688 * @return mixed
1689 */
1690 public static function alterLogTables(&$logTableSpec) {
1691 return self::singleton()->invoke(['logTableSpec'], $logTableSpec, $_nullObject,
1692 self::$_nullObject, self::$_nullObject, self::$_nullObject,
1693 self::$_nullObject,
1694 'civicrm_alterLogTables'
1695 );
1696 }
1697
1698 /**
1699 * This hook is called when a module-extension is installed.
1700 * Each module will receive hook_civicrm_install during its own installation (but not during the
1701 * installation of unrelated modules).
1702 */
1703 public static function install() {
1704 return self::singleton()->invoke(0, self::$_nullObject,
1705 self::$_nullObject, self::$_nullObject,
1706 self::$_nullObject, self::$_nullObject, self::$_nullObject,
1707 'civicrm_install'
1708 );
1709 }
1710
1711 /**
1712 * This hook is called when a module-extension is uninstalled.
1713 * Each module will receive hook_civicrm_uninstall during its own uninstallation (but not during the
1714 * uninstallation of unrelated modules).
1715 */
1716 public static function uninstall() {
1717 return self::singleton()->invoke(0, self::$_nullObject,
1718 self::$_nullObject, self::$_nullObject,
1719 self::$_nullObject, self::$_nullObject, self::$_nullObject,
1720 'civicrm_uninstall'
1721 );
1722 }
1723
1724 /**
1725 * This hook is called when a module-extension is re-enabled.
1726 * Each module will receive hook_civicrm_enable during its own re-enablement (but not during the
1727 * re-enablement of unrelated modules).
1728 */
1729 public static function enable() {
1730 return self::singleton()->invoke(0, self::$_nullObject,
1731 self::$_nullObject, self::$_nullObject,
1732 self::$_nullObject, self::$_nullObject, self::$_nullObject,
1733 'civicrm_enable'
1734 );
1735 }
1736
1737 /**
1738 * This hook is called when a module-extension is disabled.
1739 * Each module will receive hook_civicrm_disable during its own disablement (but not during the
1740 * disablement of unrelated modules).
1741 */
1742 public static function disable() {
1743 return self::singleton()->invoke(0, self::$_nullObject,
1744 self::$_nullObject, self::$_nullObject,
1745 self::$_nullObject, self::$_nullObject, self::$_nullObject,
1746 'civicrm_disable'
1747 );
1748 }
1749
1750 /**
1751 * Alter redirect.
1752 *
1753 * This hook is called when the browser is being re-directed and allows the url
1754 * to be altered.
1755 *
1756 * @param \Psr\Http\Message\UriInterface $url
1757 * @param array $context
1758 * Additional information about context
1759 * - output - if this is 'json' then it will return json.
1760 *
1761 * @return null
1762 * the return value is ignored
1763 */
1764 public static function alterRedirect(&$url, &$context) {
1765 return self::singleton()->invoke(['url', 'context'], $url,
1766 $context, self::$_nullObject,
1767 self::$_nullObject, self::$_nullObject, self::$_nullObject,
1768 'civicrm_alterRedirect'
1769 );
1770 }
1771
1772 /**
1773 * @param $varType
1774 * @param $var
1775 * @param $object
1776 *
1777 * @return mixed
1778 */
1779 public static function alterReportVar($varType, &$var, &$object) {
1780 return self::singleton()->invoke(['varType', 'var', 'object'], $varType, $var, $object,
1781 self::$_nullObject,
1782 self::$_nullObject, self::$_nullObject,
1783 'civicrm_alterReportVar'
1784 );
1785 }
1786
1787 /**
1788 * This hook is called to drive database upgrades for extension-modules.
1789 *
1790 * @param string $op
1791 * The type of operation being performed; 'check' or 'enqueue'.
1792 * @param CRM_Queue_Queue $queue
1793 * (for 'enqueue') the modifiable list of pending up upgrade tasks.
1794 *
1795 * @return bool|null
1796 * NULL, if $op is 'enqueue'.
1797 * TRUE, if $op is 'check' and upgrades are pending.
1798 * FALSE, if $op is 'check' and upgrades are not pending.
1799 */
1800 public static function upgrade($op, CRM_Queue_Queue $queue = NULL) {
1801 return self::singleton()->invoke(['op', 'queue'], $op, $queue,
1802 self::$_nullObject, self::$_nullObject, self::$_nullObject,
1803 self::$_nullObject,
1804 'civicrm_upgrade'
1805 );
1806 }
1807
1808 /**
1809 * This hook is called when an email has been successfully sent by CiviCRM, but not on an error.
1810 *
1811 * @param array $params
1812 * The mailing parameters. Array fields include: groupName, from, toName,
1813 * toEmail, subject, cc, bcc, text, html, returnPath, replyTo, headers,
1814 * attachments (array)
1815 *
1816 * @return mixed
1817 */
1818 public static function postEmailSend(&$params) {
1819 return self::singleton()->invoke(['params'], $params,
1820 self::$_nullObject, self::$_nullObject,
1821 self::$_nullObject, self::$_nullObject, self::$_nullObject,
1822 'civicrm_postEmailSend'
1823 );
1824 }
1825
1826 /**
1827 * This hook is called when a CiviMail mailing has completed
1828 *
1829 * @param int $mailingId
1830 * Mailing ID
1831 *
1832 * @return mixed
1833 */
1834 public static function postMailing($mailingId) {
1835 return self::singleton()->invoke(['mailingId'], $mailingId,
1836 self::$_nullObject, self::$_nullObject,
1837 self::$_nullObject, self::$_nullObject, self::$_nullObject,
1838 'civicrm_postMailing'
1839 );
1840 }
1841
1842 /**
1843 * This hook is called when Settings specifications are loaded.
1844 *
1845 * @param array $settingsFolders
1846 * List of paths from which to derive metadata
1847 *
1848 * @return mixed
1849 */
1850 public static function alterSettingsFolders(&$settingsFolders) {
1851 return self::singleton()->invoke(['settingsFolders'], $settingsFolders,
1852 self::$_nullObject, self::$_nullObject,
1853 self::$_nullObject, self::$_nullObject, self::$_nullObject,
1854 'civicrm_alterSettingsFolders'
1855 );
1856 }
1857
1858 /**
1859 * This hook is called when Settings have been loaded from the xml
1860 * It is an opportunity for hooks to alter the data
1861 *
1862 * @param array $settingsMetaData
1863 * Settings Metadata.
1864 * @param int $domainID
1865 * @param mixed $profile
1866 *
1867 * @return mixed
1868 */
1869 public static function alterSettingsMetaData(&$settingsMetaData, $domainID, $profile) {
1870 return self::singleton()->invoke(['settingsMetaData', 'domainID', 'profile'], $settingsMetaData,
1871 $domainID, $profile,
1872 self::$_nullObject, self::$_nullObject, self::$_nullObject,
1873 'civicrm_alterSettingsMetaData'
1874 );
1875 }
1876
1877 /**
1878 * This hook is called before running an api call.
1879 *
1880 * @param API_Wrapper[] $wrappers
1881 * (see CRM_Utils_API_ReloadOption as an example)
1882 * @param mixed $apiRequest
1883 *
1884 * @return null
1885 * The return value is ignored
1886 */
1887 public static function apiWrappers(&$wrappers, $apiRequest) {
1888 return self::singleton()
1889 ->invoke(['wrappers', 'apiRequest'], $wrappers, $apiRequest, self::$_nullObject, self::$_nullObject, self::$_nullObject,
1890 self::$_nullObject, 'civicrm_apiWrappers'
1891 );
1892 }
1893
1894 /**
1895 * This hook is called before running pending cron jobs.
1896 *
1897 * @param CRM_Core_JobManager $jobManager
1898 *
1899 * @return null
1900 * The return value is ignored.
1901 */
1902 public static function cron($jobManager) {
1903 return self::singleton()->invoke(['jobManager'],
1904 $jobManager, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
1905 'civicrm_cron'
1906 );
1907 }
1908
1909 /**
1910 * This hook is called when loading CMS permissions; use this hook to modify
1911 * the array of system permissions for CiviCRM.
1912 *
1913 * @param array $permissions
1914 * Array of permissions. See CRM_Core_Permission::getCorePermissions() for
1915 * the format of this array.
1916 *
1917 * @return null
1918 * The return value is ignored
1919 */
1920 public static function permission(&$permissions) {
1921 return self::singleton()->invoke(['permissions'], $permissions,
1922 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
1923 'civicrm_permission'
1924 );
1925 }
1926
1927 /**
1928 * This hook is called when checking permissions; use this hook to dynamically
1929 * escalate user permissions in certain use cases (cf. CRM-19256).
1930 *
1931 * @param string $permission
1932 * The name of an atomic permission, ie. 'access deleted contacts'
1933 * @param bool $granted
1934 * Whether this permission is currently granted. The hook can change this value.
1935 * @param int $contactId
1936 * Contact whose permissions we are checking (if null, assume current user).
1937 *
1938 * @return null
1939 * The return value is ignored
1940 */
1941 public static function permission_check($permission, &$granted, $contactId) {
1942 return self::singleton()->invoke(['permission', 'granted', 'contactId'], $permission, $granted, $contactId,
1943 self::$_nullObject, self::$_nullObject, self::$_nullObject,
1944 'civicrm_permission_check'
1945 );
1946 }
1947
1948 /**
1949 * @param CRM_Core_Exception $exception
1950 * @param mixed $request
1951 * Reserved for future use.
1952 */
1953 public static function unhandledException($exception, $request = NULL) {
1954 $event = new \Civi\Core\Event\UnhandledExceptionEvent($exception, self::$_nullObject);
1955 \Civi::dispatcher()->dispatch('hook_civicrm_unhandled_exception', $event);
1956 }
1957
1958 /**
1959 * This hook is called for declaring managed entities via API.
1960 *
1961 * Note: This is a pre-boot hook. It will dispatch via the extension/module
1962 * subsystem but *not* the Symfony EventDispatcher.
1963 *
1964 * @param array[] $entityTypes
1965 * List of entity types; each entity-type is an array with keys:
1966 * - name: string, a unique short name (e.g. "ReportInstance")
1967 * - class: string, a PHP DAO class (e.g. "CRM_Report_DAO_Instance")
1968 * - table: string, a SQL table name (e.g. "civicrm_report_instance")
1969 * - fields_callback: array, list of callables which manipulates field list
1970 * - links_callback: array, list of callables which manipulates fk list
1971 *
1972 * @return null
1973 * The return value is ignored
1974 */
1975 public static function entityTypes(&$entityTypes) {
1976 return self::singleton()->invoke(['entityTypes'], $entityTypes, self::$_nullObject, self::$_nullObject,
1977 self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_entityTypes'
1978 );
1979 }
1980
1981 /**
1982 * Build a description of available hooks.
1983 *
1984 * @param \Civi\Core\CiviEventInspector $inspector
1985 */
1986 public static function eventDefs($inspector) {
1987 $event = \Civi\Core\Event\GenericHookEvent::create([
1988 'inspector' => $inspector,
1989 ]);
1990 Civi::dispatcher()->dispatch('hook_civicrm_eventDefs', $event);
1991 }
1992
1993 /**
1994 * This hook is called while preparing a profile form.
1995 *
1996 * @param string $profileName
1997 * @return mixed
1998 */
1999 public static function buildProfile($profileName) {
2000 return self::singleton()->invoke(['profileName'], $profileName, self::$_nullObject, self::$_nullObject, self::$_nullObject,
2001 self::$_nullObject, self::$_nullObject, 'civicrm_buildProfile');
2002 }
2003
2004 /**
2005 * This hook is called while validating a profile form submission.
2006 *
2007 * @param string $profileName
2008 * @return mixed
2009 */
2010 public static function validateProfile($profileName) {
2011 return self::singleton()->invoke(['profileName'], $profileName, self::$_nullObject, self::$_nullObject, self::$_nullObject,
2012 self::$_nullObject, self::$_nullObject, 'civicrm_validateProfile');
2013 }
2014
2015 /**
2016 * This hook is called processing a valid profile form submission.
2017 *
2018 * @param string $profileName
2019 * @return mixed
2020 */
2021 public static function processProfile($profileName) {
2022 return self::singleton()->invoke(['profileName'], $profileName, self::$_nullObject, self::$_nullObject, self::$_nullObject,
2023 self::$_nullObject, self::$_nullObject, 'civicrm_processProfile');
2024 }
2025
2026 /**
2027 * This hook is called while preparing a read-only profile screen
2028 *
2029 * @param string $profileName
2030 * @return mixed
2031 */
2032 public static function viewProfile($profileName) {
2033 return self::singleton()->invoke(['profileName'], $profileName, self::$_nullObject, self::$_nullObject, self::$_nullObject,
2034 self::$_nullObject, self::$_nullObject, 'civicrm_viewProfile');
2035 }
2036
2037 /**
2038 * This hook is called while preparing a list of contacts (based on a profile)
2039 *
2040 * @param string $profileName
2041 * @return mixed
2042 */
2043 public static function searchProfile($profileName) {
2044 return self::singleton()->invoke(['profileName'], $profileName, self::$_nullObject, self::$_nullObject, self::$_nullObject,
2045 self::$_nullObject, self::$_nullObject, 'civicrm_searchProfile');
2046 }
2047
2048 /**
2049 * This hook is invoked when building a CiviCRM name badge.
2050 *
2051 * @param string $labelName
2052 * String referencing name of badge format.
2053 * @param object $label
2054 * Reference to the label object.
2055 * @param array $format
2056 * Array of format data.
2057 * @param array $participant
2058 * Array of participant values.
2059 *
2060 * @return null
2061 * the return value is ignored
2062 */
2063 public static function alterBadge($labelName, &$label, &$format, &$participant) {
2064 return self::singleton()
2065 ->invoke(['labelName', 'label', 'format', 'participant'], $labelName, $label, $format, $participant, self::$_nullObject, self::$_nullObject, 'civicrm_alterBadge');
2066 }
2067
2068 /**
2069 * This hook is called before encoding data in barcode.
2070 *
2071 * @param array $data
2072 * Associated array of values available for encoding.
2073 * @param string $type
2074 * Type of barcode, classic barcode or QRcode.
2075 * @param string $context
2076 * Where this hooks is invoked.
2077 *
2078 * @return mixed
2079 */
2080 public static function alterBarcode(&$data, $type = 'barcode', $context = 'name_badge') {
2081 return self::singleton()->invoke(['data', 'type', 'context'], $data, $type, $context, self::$_nullObject,
2082 self::$_nullObject, self::$_nullObject, 'civicrm_alterBarcode');
2083 }
2084
2085 /**
2086 * Modify or replace the Mailer object used for outgoing mail.
2087 *
2088 * @param object $mailer
2089 * The default mailer produced by normal configuration; a PEAR "Mail" class (like those returned by Mail::factory)
2090 * @param string $driver
2091 * The type of the default mailer (eg "smtp", "sendmail", "mock", "CRM_Mailing_BAO_Spool")
2092 * @param array $params
2093 * The default mailer config options
2094 *
2095 * @return mixed
2096 * @see Mail::factory
2097 */
2098 public static function alterMailer(&$mailer, $driver, $params) {
2099 return self::singleton()
2100 ->invoke(['mailer', 'driver', 'params'], $mailer, $driver, $params, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_alterMailer');
2101 }
2102
2103 /**
2104 * Deprecated: Misnamed version of alterMailer(). Remove post-4.7.x.
2105 * Modify or replace the Mailer object used for outgoing mail.
2106 *
2107 * @param object $mailer
2108 * The default mailer produced by normal configuration; a PEAR "Mail" class (like those returned by Mail::factory)
2109 * @param string $driver
2110 * The type of the default mailer (eg "smtp", "sendmail", "mock", "CRM_Mailing_BAO_Spool")
2111 * @param array $params
2112 * The default mailer config options
2113 *
2114 * @return mixed
2115 * @see Mail::factory
2116 * @deprecated
2117 */
2118 public static function alterMail(&$mailer, $driver, $params) {
2119 // This has been deprecated on the premise it MIGHT be called externally for a long time.
2120 // We don't have a clear policy on how much we support external extensions calling internal
2121 // hooks (ie. in general we say 'don't call internal functions', but some hooks like pre hooks
2122 // are expected to be called externally.
2123 // It's really really unlikely anyone uses this - but let's add deprecations for a couple
2124 // of releases first.
2125 CRM_Core_Error::deprecatedFunctionWarning('CRM_Utils_Hook::alterMailer');
2126 return CRM_Utils_Hook::alterMailer($mailer, $driver, $params);
2127 }
2128
2129 /**
2130 * This hook is called while building the core search query,
2131 * so hook implementers can provide their own query objects which alters/extends core search.
2132 *
2133 * @param array $queryObjects
2134 * @param string $type
2135 *
2136 * @return mixed
2137 */
2138 public static function queryObjects(&$queryObjects, $type = 'Contact') {
2139 return self::singleton()
2140 ->invoke(['queryObjects', 'type'], $queryObjects, $type, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_queryObjects');
2141 }
2142
2143 /**
2144 * This hook is called while viewing contact dashboard.
2145 *
2146 * @param array $availableDashlets
2147 * List of dashlets; each is formatted per api/v3/Dashboard
2148 * @param array $defaultDashlets
2149 * List of dashlets; each is formatted per api/v3/DashboardContact
2150 *
2151 * @return mixed
2152 */
2153 public static function dashboard_defaults($availableDashlets, &$defaultDashlets) {
2154 return self::singleton()
2155 ->invoke(['availableDashlets', 'defaultDashlets'], $availableDashlets, $defaultDashlets, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_dashboard_defaults');
2156 }
2157
2158 /**
2159 * This hook is called before a case merge (or a case reassign)
2160 *
2161 * @param int $mainContactId
2162 * @param int $mainCaseId
2163 * @param int $otherContactId
2164 * @param int $otherCaseId
2165 * @param bool $changeClient
2166 *
2167 * @return mixed
2168 */
2169 public static function pre_case_merge($mainContactId, $mainCaseId = NULL, $otherContactId = NULL, $otherCaseId = NULL, $changeClient = FALSE) {
2170 return self::singleton()
2171 ->invoke(['mainContactId', 'mainCaseId', 'otherContactId', 'otherCaseId', 'changeClient'], $mainContactId, $mainCaseId, $otherContactId, $otherCaseId, $changeClient, self::$_nullObject, 'civicrm_pre_case_merge');
2172 }
2173
2174 /**
2175 * This hook is called after a case merge (or a case reassign)
2176 *
2177 * @param int $mainContactId
2178 * @param int $mainCaseId
2179 * @param int $otherContactId
2180 * @param int $otherCaseId
2181 * @param bool $changeClient
2182 *
2183 * @return mixed
2184 */
2185 public static function post_case_merge($mainContactId, $mainCaseId = NULL, $otherContactId = NULL, $otherCaseId = NULL, $changeClient = FALSE) {
2186 return self::singleton()
2187 ->invoke(['mainContactId', 'mainCaseId', 'otherContactId', 'otherCaseId', 'changeClient'], $mainContactId, $mainCaseId, $otherContactId, $otherCaseId, $changeClient, self::$_nullObject, 'civicrm_post_case_merge');
2188 }
2189
2190 /**
2191 * Issue CRM-14276
2192 * Add a hook for altering the display name
2193 *
2194 * hook_civicrm_contact_get_displayname(&$display_name, $objContact)
2195 *
2196 * @param string $displayName
2197 * @param int $contactId
2198 * @param object $dao
2199 * The contact object.
2200 *
2201 * @return mixed
2202 */
2203 public static function alterDisplayName(&$displayName, $contactId, $dao) {
2204 return self::singleton()->invoke(['displayName', 'contactId', 'dao'],
2205 $displayName, $contactId, $dao, self::$_nullObject, self::$_nullObject,
2206 self::$_nullObject, 'civicrm_contact_get_displayname'
2207 );
2208 }
2209
2210 /**
2211 * Modify the CRM_Core_Resources settings data.
2212 *
2213 * @param array $data
2214 * @see CRM_Core_Resources::addSetting
2215 */
2216 public static function alterResourceSettings(&$data) {
2217 $event = \Civi\Core\Event\GenericHookEvent::create([
2218 'data' => &$data,
2219 ]);
2220 Civi::dispatcher()->dispatch('hook_civicrm_alterResourceSettings', $event);
2221 }
2222
2223 /**
2224 * EXPERIMENTAL: This hook allows one to register additional Angular modules
2225 *
2226 * @param array $angularModules
2227 * List of modules. Each module defines:
2228 * - ext: string, the CiviCRM extension which hosts the files.
2229 * - js: array, list of JS files or globs.
2230 * - css: array, list of CSS files or globs.
2231 * - partials: array, list of base-dirs containing HTML.
2232 * - requires: array, list of required Angular modules.
2233 * - basePages: array, uncondtionally load this module onto the given Angular pages. [v4.7.21+]
2234 * If omitted, default to "array('civicrm/a')" for backward compat.
2235 * For a utility that should only be loaded on-demand, use "array()".
2236 * For a utility that should be loaded in all pages use, "array('*')".
2237 * @return null
2238 * the return value is ignored
2239 *
2240 * @code
2241 * function mymod_civicrm_angularModules(&$angularModules) {
2242 * $angularModules['myAngularModule'] = array(
2243 * 'ext' => 'org.example.mymod',
2244 * 'js' => array('js/myAngularModule.js'),
2245 * );
2246 * $angularModules['myBigAngularModule'] = array(
2247 * 'ext' => 'org.example.mymod',
2248 * 'js' => array('js/part1.js', 'js/part2.js', 'ext://other.ext.name/file.js', 'assetBuilder://dynamicAsset.js'),
2249 * 'css' => array('css/myAngularModule.css', 'ext://other.ext.name/file.css', 'assetBuilder://dynamicAsset.css'),
2250 * 'partials' => array('partials/myBigAngularModule'),
2251 * 'requires' => array('otherModuleA', 'otherModuleB'),
2252 * 'basePages' => array('civicrm/a'),
2253 * );
2254 * }
2255 * @endcode
2256 */
2257 public static function angularModules(&$angularModules) {
2258 return self::singleton()->invoke(['angularModules'], $angularModules,
2259 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
2260 'civicrm_angularModules'
2261 );
2262 }
2263
2264 /**
2265 * Alter the definition of some Angular HTML partials.
2266 *
2267 * @param \Civi\Angular\Manager $angular
2268 *
2269 * @code
2270 * function example_civicrm_alterAngular($angular) {
2271 * $changeSet = \Civi\Angular\ChangeSet::create('mychanges')
2272 * ->alterHtml('~/crmMailing/EditMailingCtrl/2step.html', function(phpQueryObject $doc) {
2273 * $doc->find('[ng-form="crmMailingSubform"]')->attr('cat-stevens', 'ts(\'wild world\')');
2274 * })
2275 * );
2276 * $angular->add($changeSet);
2277 * }
2278 * @endCode
2279 */
2280 public static function alterAngular($angular) {
2281 $event = \Civi\Core\Event\GenericHookEvent::create([
2282 'angular' => $angular,
2283 ]);
2284 Civi::dispatcher()->dispatch('hook_civicrm_alterAngular', $event);
2285 }
2286
2287 /**
2288 * This hook is called when building a link to a semi-static asset.
2289 *
2290 * @param string $asset
2291 * The name of the asset.
2292 * Ex: 'angular.json'
2293 * @param array $params
2294 * List of optional arguments which influence the content.
2295 * @return null
2296 * the return value is ignored
2297 */
2298 public static function getAssetUrl(&$asset, &$params) {
2299 return self::singleton()->invoke(['asset', 'params'],
2300 $asset, $params, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
2301 'civicrm_getAssetUrl'
2302 );
2303 }
2304
2305 /**
2306 * This hook is called whenever the system builds a new copy of
2307 * semi-static asset.
2308 *
2309 * @param string $asset
2310 * The name of the asset.
2311 * Ex: 'angular.json'
2312 * @param array $params
2313 * List of optional arguments which influence the content.
2314 * Note: Params are immutable because they are part of the cache-key.
2315 * @param string $mimeType
2316 * Initially, NULL. Modify to specify the mime-type.
2317 * @param string $content
2318 * Initially, NULL. Modify to specify the rendered content.
2319 * @return null
2320 * the return value is ignored
2321 */
2322 public static function buildAsset($asset, $params, &$mimeType, &$content) {
2323 return self::singleton()->invoke(['asset', 'params', 'mimeType', 'content'],
2324 $asset, $params, $mimeType, $content, self::$_nullObject, self::$_nullObject,
2325 'civicrm_buildAsset'
2326 );
2327 }
2328
2329 /**
2330 * This hook fires whenever a record in a case changes.
2331 *
2332 * @param \Civi\CCase\Analyzer $analyzer
2333 * A bundle of data about the case (such as the case and activity records).
2334 */
2335 public static function caseChange(\Civi\CCase\Analyzer $analyzer) {
2336 $event = new \Civi\CCase\Event\CaseChangeEvent($analyzer);
2337 \Civi::dispatcher()->dispatch('hook_civicrm_caseChange', $event);
2338 }
2339
2340 /**
2341 * Generate a default CRUD URL for an entity.
2342 *
2343 * @param array $spec
2344 * With keys:.
2345 * - action: int, eg CRM_Core_Action::VIEW or CRM_Core_Action::UPDATE
2346 * - entity_table: string
2347 * - entity_id: int
2348 * @param CRM_Core_DAO $bao
2349 * @param array $link
2350 * To define the link, add these keys to $link:.
2351 * - title: string
2352 * - path: string
2353 * - query: array
2354 * - url: string (used in lieu of "path"/"query")
2355 * Note: if making "url" CRM_Utils_System::url(), set $htmlize=false
2356 * @return mixed
2357 */
2358 public static function crudLink($spec, $bao, &$link) {
2359 return self::singleton()->invoke(['spec', 'bao', 'link'], $spec, $bao, $link,
2360 self::$_nullObject, self::$_nullObject, self::$_nullObject,
2361 'civicrm_crudLink'
2362 );
2363 }
2364
2365 /**
2366 * Modify the CiviCRM container - add new services, parameters, extensions, etc.
2367 *
2368 * @code
2369 * use Symfony\Component\Config\Resource\FileResource;
2370 * use Symfony\Component\DependencyInjection\Definition;
2371 *
2372 * function mymodule_civicrm_container($container) {
2373 * $container->addResource(new FileResource(__FILE__));
2374 * $container->setDefinition('mysvc', new Definition('My\Class', array()));
2375 * }
2376 * @endcode
2377 *
2378 * Tip: The container configuration will be compiled/cached. The default cache
2379 * behavior is aggressive. When you first implement the hook, be sure to
2380 * flush the cache. Additionally, you should relax caching during development.
2381 * In `civicrm.settings.php`, set define('CIVICRM_CONTAINER_CACHE', 'auto').
2382 *
2383 * Note: This is a preboot hook. It will dispatch via the extension/module
2384 * subsystem but *not* the Symfony EventDispatcher.
2385 *
2386 * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
2387 * @see http://symfony.com/doc/current/components/dependency_injection/index.html
2388 */
2389 public static function container(\Symfony\Component\DependencyInjection\ContainerBuilder $container) {
2390 self::singleton()->invoke(['container'], $container, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_container');
2391 }
2392
2393 /**
2394 * @param array $fileSearches CRM_Core_FileSearchInterface
2395 * @return mixed
2396 */
2397 public static function fileSearches(&$fileSearches) {
2398 return self::singleton()->invoke(['fileSearches'], $fileSearches,
2399 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
2400 'civicrm_fileSearches'
2401 );
2402 }
2403
2404 /**
2405 * Check system status.
2406 *
2407 * @param array $messages
2408 * Array<CRM_Utils_Check_Message>. A list of messages regarding system status.
2409 * @return mixed
2410 */
2411 public static function check(&$messages) {
2412 return self::singleton()
2413 ->invoke(['messages'], $messages, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_check');
2414 }
2415
2416 /**
2417 * This hook is called when a query string of the CSV Batch export is generated.
2418 *
2419 * @param string $query
2420 *
2421 * @return mixed
2422 */
2423 public static function batchQuery(&$query) {
2424 return self::singleton()->invoke(['query'], $query, self::$_nullObject,
2425 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
2426 'civicrm_batchQuery'
2427 );
2428 }
2429
2430 /**
2431 * This hook is called to alter Deferred revenue item values just before they are
2432 * inserted in civicrm_financial_trxn table
2433 *
2434 * @param array $deferredRevenues
2435 *
2436 * @param array $contributionDetails
2437 *
2438 * @param bool $update
2439 *
2440 * @param string $context
2441 *
2442 * @return mixed
2443 */
2444 public static function alterDeferredRevenueItems(&$deferredRevenues, $contributionDetails, $update, $context) {
2445 return self::singleton()->invoke(['deferredRevenues', 'contributionDetails', 'update', 'context'], $deferredRevenues, $contributionDetails, $update, $context,
2446 self::$_nullObject, self::$_nullObject, 'civicrm_alterDeferredRevenueItems'
2447 );
2448 }
2449
2450 /**
2451 * This hook is called when the entries of the CSV Batch export are mapped.
2452 *
2453 * @param array $results
2454 * @param array $items
2455 *
2456 * @return mixed
2457 */
2458 public static function batchItems(&$results, &$items) {
2459 return self::singleton()->invoke(['results', 'items'], $results, $items,
2460 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
2461 'civicrm_batchItems'
2462 );
2463 }
2464
2465 /**
2466 * This hook is called when core resources are being loaded
2467 *
2468 * @see CRM_Core_Resources::coreResourceList
2469 *
2470 * @param array $list
2471 * @param string $region
2472 */
2473 public static function coreResourceList(&$list, $region) {
2474 self::singleton()->invoke(['list', 'region'], $list, $region,
2475 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
2476 'civicrm_coreResourceList'
2477 );
2478 }
2479
2480 /**
2481 * Allows the list of filters on the EntityRef widget to be altered.
2482 *
2483 * @see CRM_Core_Resources::entityRefFilters
2484 *
2485 * @param array $filters
2486 */
2487 public static function entityRefFilters(&$filters) {
2488 self::singleton()->invoke(['filters'], $filters, self::$_nullObject, self::$_nullObject,
2489 self::$_nullObject, self::$_nullObject, self::$_nullObject,
2490 'civicrm_entityRefFilters'
2491 );
2492 }
2493
2494 /**
2495 * This hook is called for bypass a few civicrm urls from IDS check.
2496 *
2497 * @param array $skip list of civicrm urls
2498 *
2499 * @return mixed
2500 */
2501 public static function idsException(&$skip) {
2502 return self::singleton()->invoke(['skip'], $skip, self::$_nullObject,
2503 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
2504 'civicrm_idsException'
2505 );
2506 }
2507
2508 /**
2509 * This hook is called when a geocoder's format method is called.
2510 *
2511 * @param string $geoProvider
2512 * @param array $values
2513 * @param SimpleXMLElement $xml
2514 *
2515 * @return mixed
2516 */
2517 public static function geocoderFormat($geoProvider, &$values, $xml) {
2518 return self::singleton()->invoke(['geoProvider', 'values', 'xml'], $geoProvider, $values, $xml,
2519 self::$_nullObject, self::$_nullObject, self::$_nullObject,
2520 'civicrm_geocoderFormat'
2521 );
2522 }
2523
2524 /**
2525 * This hook is called before an inbound SMS is processed.
2526 *
2527 * @param \CRM_SMS_Message $message
2528 * An SMS message received
2529 * @return mixed
2530 */
2531 public static function inboundSMS(&$message) {
2532 return self::singleton()->invoke(['message'], $message, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_inboundSMS');
2533 }
2534
2535 /**
2536 * This hook is called to modify api params of EntityRef form field
2537 *
2538 * @param array $params
2539 * @param string $formName
2540 * @return mixed
2541 */
2542 public static function alterEntityRefParams(&$params, $formName) {
2543 return self::singleton()->invoke(['params', 'formName'], $params, $formName,
2544 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
2545 'civicrm_alterEntityRefParams'
2546 );
2547 }
2548
2549 /**
2550 * This hook is called before a scheduled job is executed
2551 *
2552 * @param CRM_Core_DAO_Job $job
2553 * The job to be executed
2554 * @param array $params
2555 * The arguments to be given to the job
2556 */
2557 public static function preJob($job, $params) {
2558 return self::singleton()->invoke(['job', 'params'], $job, $params,
2559 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
2560 'civicrm_preJob'
2561 );
2562 }
2563
2564 /**
2565 * This hook is called after a scheduled job is executed
2566 *
2567 * @param CRM_Core_DAO_Job $job
2568 * The job that was executed
2569 * @param array $params
2570 * The arguments given to the job
2571 * @param array $result
2572 * The result of the API call, or the thrown exception if any
2573 */
2574 public static function postJob($job, $params, $result) {
2575 return self::singleton()->invoke(['job', 'params', 'result'], $job, $params, $result,
2576 self::$_nullObject, self::$_nullObject, self::$_nullObject,
2577 'civicrm_postJob'
2578 );
2579 }
2580
2581 /**
2582 * This hook is called before and after constructing mail recipients.
2583 * Allows user to alter filter and/or search query to fetch mail recipients
2584 *
2585 * @param CRM_Mailing_DAO_Mailing $mailingObject
2586 * @param array $criteria
2587 * A list of SQL criteria; you can add/remove/replace/modify criteria.
2588 * Array(string $name => CRM_Utils_SQL_Select $criterion).
2589 * Ex: array('do_not_email' => CRM_Utils_SQL_Select::fragment()->where("$contact.do_not_email = 0")).
2590 * @param string $context
2591 * Ex: 'pre', 'post'
2592 * @return mixed
2593 */
2594 public static function alterMailingRecipients(&$mailingObject, &$criteria, $context) {
2595 return self::singleton()->invoke(['mailingObject', 'params', 'context'],
2596 $mailingObject, $criteria, $context,
2597 self::$_nullObject, self::$_nullObject, self::$_nullObject,
2598 'civicrm_alterMailingRecipients'
2599 );
2600 }
2601
2602 /**
2603 * ALlow Extensions to custom process IPN hook data such as sending Google Analyitcs information based on the IPN
2604 * @param array $IPNData - Array of IPN Data
2605 * @return mixed
2606 */
2607 public static function postIPNProcess(&$IPNData) {
2608 return self::singleton()->invoke(['IPNData'],
2609 $IPNData, self::$_nullObject, self::$_nullObject,
2610 self::$_nullObject, self::$_nullObject, self::$_nullObject,
2611 'civicrm_postIPNProcess'
2612 );
2613 }
2614
2615 }