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