INFRA-132 - Docblock @param and @return tag fixes
[civicrm-core.git] / CRM / Utils / Hook.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
32 * $Id: $
33 *
34 */
35 abstract class CRM_Utils_Hook {
36
37 // Allowed values for dashboard hook content placement
38 // Default - place content below activity list
39 const DASHBOARD_BELOW = 1;
40 // Place content above activity list
41 const DASHBOARD_ABOVE = 2;
42 // Don't display activity list at all
43 const DASHBOARD_REPLACE = 3;
44
45 // by default - place content below existing content
46 const SUMMARY_BELOW = 1;
47 // pace hook content above
48 const SUMMARY_ABOVE = 2;
49 // create your own summarys
50 const SUMMARY_REPLACE = 3;
51
52 static $_nullObject = NULL;
53
54 /**
55 * We only need one instance of this object. So we use the singleton
56 * pattern and cache the instance in this variable
57 *
58 * @var object
59 * @static
60 */
61 static private $_singleton = NULL;
62
63 /**
64 * @var bool
65 */
66 private $commonIncluded = FALSE;
67
68 /**
69 * @var array(string)
70 */
71 private $commonCiviModules = array();
72
73 /**
74 * Constructor and getter for the singleton instance
75 *
76 * @param bool $fresh
77 *
78 * @return self
79 * An instance of $config->userHookClass
80 */
81 public static function singleton($fresh = FALSE) {
82 if (self::$_singleton == NULL || $fresh) {
83 $config = CRM_Core_Config::singleton();
84 $class = $config->userHookClass;
85 require_once str_replace('_', DIRECTORY_SEPARATOR, $config->userHookClass) . '.php';
86 self::$_singleton = new $class();
87 }
88 return self::$_singleton;
89 }
90
91 /**
92 * Invoke hooks
93 *
94 * @param int $numParams
95 * Number of parameters to pass to the hook.
96 * @param mixed $arg1
97 * Parameter to be passed to the hook.
98 * @param mixed $arg2
99 * Parameter to be passed to the hook.
100 * @param mixed $arg3
101 * Parameter to be passed to the hook.
102 * @param mixed $arg4
103 * Parameter to be passed to the hook.
104 * @param mixed $arg5
105 * Parameter to be passed to the hook.
106 * @param mixed $arg6
107 * Parameter to be passed to the hook.
108 * @param string $fnSuffix
109 * Function suffix, this is effectively the hook name.
110 *
111 * @return mixed
112 */
113 public abstract function invoke(
114 $numParams,
115 &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6,
116 $fnSuffix
117 );
118
119 /**
120 * @param array $numParams
121 * @param $arg1
122 * @param $arg2
123 * @param $arg3
124 * @param $arg4
125 * @param $arg5
126 * @param $arg6
127 * @param $fnSuffix
128 * @param $fnPrefix
129 *
130 * @return array|bool
131 */
132 public function commonInvoke(
133 $numParams,
134 &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6,
135 $fnSuffix, $fnPrefix
136 ) {
137
138 $this->commonBuildModuleList($fnPrefix);
139
140 return $this->runHooks($this->commonCiviModules, $fnSuffix,
141 $numParams, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6
142 );
143 }
144
145 /**
146 * Build the list of modules to be processed for hooks.
147 *
148 * @param string $fnPrefix
149 */
150 public function commonBuildModuleList($fnPrefix) {
151 if (!$this->commonIncluded) {
152 // include external file
153 $this->commonIncluded = TRUE;
154
155 $config = CRM_Core_Config::singleton();
156 if (!empty($config->customPHPPathDir) &&
157 file_exists("{$config->customPHPPathDir}/civicrmHooks.php")
158 ) {
159 @include_once "civicrmHooks.php";
160 }
161
162 if (!empty($fnPrefix)) {
163 $this->commonCiviModules[$fnPrefix] = $fnPrefix;
164 }
165
166 $this->requireCiviModules($this->commonCiviModules);
167 }
168 }
169
170 /**
171 * @param $civiModules
172 * @param $fnSuffix
173 * @param array $numParams
174 * @param $arg1
175 * @param $arg2
176 * @param $arg3
177 * @param $arg4
178 * @param $arg5
179 * @param $arg6
180 *
181 * @return array|bool
182 */
183 public function runHooks(
184 $civiModules, $fnSuffix, $numParams,
185 &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6
186 ) {
187 // $civiModules is *not* passed by reference because runHooks
188 // must be reentrant. PHP is finicky about running
189 // multiple loops over the same variable. The circumstances
190 // to reproduce the issue are pretty intricate.
191 $result = array();
192
193 if ($civiModules !== NULL) {
194 foreach ($civiModules as $module) {
195 $fnName = "{$module}_{$fnSuffix}";
196 if (function_exists($fnName)) {
197 $fResult = array();
198 switch ($numParams) {
199 case 0:
200 $fResult = $fnName();
201 break;
202
203 case 1:
204 $fResult = $fnName($arg1);
205 break;
206
207 case 2:
208 $fResult = $fnName($arg1, $arg2);
209 break;
210
211 case 3:
212 $fResult = $fnName($arg1, $arg2, $arg3);
213 break;
214
215 case 4:
216 $fResult = $fnName($arg1, $arg2, $arg3, $arg4);
217 break;
218
219 case 5:
220 $fResult = $fnName($arg1, $arg2, $arg3, $arg4, $arg5);
221 break;
222
223 case 6:
224 $fResult = $fnName($arg1, $arg2, $arg3, $arg4, $arg5, $arg6);
225 break;
226
227 default:
228 CRM_Core_Error::fatal(ts('Invalid hook invocation'));
229 break;
230 }
231
232 if (!empty($fResult) &&
233 is_array($fResult)
234 ) {
235 $result = array_merge($result, $fResult);
236 }
237 }
238 }
239 }
240
241 return empty($result) ? TRUE : $result;
242 }
243
244 /**
245 * @param $moduleList
246 */
247 public function requireCiviModules(&$moduleList) {
248 $civiModules = CRM_Core_PseudoConstant::getModuleExtensions();
249 foreach ($civiModules as $civiModule) {
250 if (!file_exists($civiModule['filePath'])) {
251 CRM_Core_Session::setStatus(
252 ts('Error loading module file (%1). Please restore the file or disable the module.',
253 array(1 => $civiModule['filePath'])),
254 ts('Warning'), 'error');
255 continue;
256 }
257 include_once $civiModule['filePath'];
258 $moduleList[$civiModule['prefix']] = $civiModule['prefix'];
259 }
260 }
261
262 /**
263 * This hook is called before a db write on some core objects.
264 * This hook does not allow the abort of the operation
265 *
266 * @param string $op
267 * The type of operation being performed.
268 * @param string $objectName
269 * The name of the object.
270 * @param int $id
271 * The object id if available.
272 * @param array $params
273 * The parameters used for object creation / editing.
274 *
275 * @return null
276 * the return value is ignored
277 */
278 public static function pre($op, $objectName, $id, &$params) {
279 $event = new \Civi\Core\Event\PreEvent($op, $objectName, $id, $params);
280 \Civi\Core\Container::singleton()->get('dispatcher')->dispatch("hook_civicrm_pre", $event);
281 \Civi\Core\Container::singleton()->get('dispatcher')->dispatch("hook_civicrm_pre::$objectName", $event);
282 return self::singleton()
283 ->invoke(4, $op, $objectName, $id, $params, self::$_nullObject, self::$_nullObject, 'civicrm_pre');
284 }
285
286 /**
287 * This hook is called after a db write on some core objects.
288 *
289 * @param string $op
290 * The type of operation being performed.
291 * @param string $objectName
292 * The name of the object.
293 * @param int $objectId
294 * The unique identifier for the object.
295 * @param object $objectRef
296 * The reference to the object if available.
297 *
298 * @return mixed
299 * based on op. pre-hooks return a boolean or
300 * an error message which aborts the operation
301 */
302 public static function post($op, $objectName, $objectId, &$objectRef) {
303 $event = new \Civi\Core\Event\PostEvent($op, $objectName, $objectId, $objectRef);
304 \Civi\Core\Container::singleton()->get('dispatcher')->dispatch("hook_civicrm_post", $event);
305 \Civi\Core\Container::singleton()->get('dispatcher')->dispatch("hook_civicrm_post::$objectName", $event);
306 return self::singleton()
307 ->invoke(4, $op, $objectName, $objectId, $objectRef, self::$_nullObject, self::$_nullObject, 'civicrm_post');
308 }
309
310 /**
311 * This hook retrieves links from other modules and injects it into
312 * the view contact tabs
313 *
314 * @param string $op
315 * The type of operation being performed.
316 * @param string $objectName
317 * The name of the object.
318 * @param int $objectId
319 * The unique identifier for the object.
320 * @param array $links
321 * (optional) the links array (introduced in v3.2).
322 * @param int $mask
323 * (optional) the bitmask to show/hide links.
324 * @param array $values
325 * (optional) the values to fill the links.
326 *
327 * @return null
328 * the return value is ignored
329 */
330 public static function links($op, $objectName, &$objectId, &$links, &$mask = NULL, &$values = array()) {
331 return self::singleton()->invoke(6, $op, $objectName, $objectId, $links, $mask, $values, 'civicrm_links');
332 }
333
334 /**
335 * This hook is invoked during the CiviCRM form preProcess phase.
336 *
337 * @param string $formName
338 * The name of the form.
339 * @param CRM_Core_Form $form
340 * Reference to the form object.
341 *
342 * @return null
343 * the return value is ignored
344 */
345 public static function preProcess($formName, &$form) {
346 return self::singleton()
347 ->invoke(2, $formName, $form, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_preProcess');
348 }
349
350 /**
351 * This hook is invoked when building a CiviCRM form. This hook should also
352 * be used to set the default values of a form element
353 *
354 * @param string $formName
355 * The name of the form.
356 * @param CRM_Core_Form $form
357 * Reference to the form object.
358 *
359 * @return null
360 * the return value is ignored
361 */
362 public static function buildForm($formName, &$form) {
363 return self::singleton()->invoke(2, $formName, $form,
364 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
365 'civicrm_buildForm'
366 );
367 }
368
369 /**
370 * This hook is invoked when a CiviCRM form is submitted. If the module has injected
371 * any form elements, this hook should save the values in the database
372 *
373 * @param string $formName
374 * The name of the form.
375 * @param CRM_Core_Form $form
376 * Reference to the form object.
377 *
378 * @return null
379 * the return value is ignored
380 */
381 public static function postProcess($formName, &$form) {
382 return self::singleton()->invoke(2, $formName, $form,
383 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
384 'civicrm_postProcess'
385 );
386 }
387
388 /**
389 * This hook is invoked during all CiviCRM form validation. An array of errors
390 * detected is returned. Else we assume validation succeeded.
391 *
392 * @param string $formName
393 * The name of the form.
394 * @param array &$fields the POST parameters as filtered by QF
395 * @param array &$files the FILES parameters as sent in by POST
396 * @param array &$form the form object
397 *
398 * @return mixed
399 * formRule hooks return a boolean or
400 * an array of error messages which display a QF Error
401 */
402 public static function validate($formName, &$fields, &$files, &$form) {
403 return self::singleton()
404 ->invoke(4, $formName, $fields, $files, $form, self::$_nullObject, self::$_nullObject, 'civicrm_validate');
405 }
406
407 /**
408 * This hook is invoked during all CiviCRM form validation. An array of errors
409 * detected is returned. Else we assume validation succeeded.
410 *
411 * @param string $formName
412 * The name of the form.
413 * @param array &$fields the POST parameters as filtered by QF
414 * @param array &$files the FILES parameters as sent in by POST
415 * @param array &$form the form object
416 * @param array &$errors the array of errors.
417 *
418 * @return mixed
419 * formRule hooks return a boolean or
420 * an array of error messages which display a QF Error
421 */
422 public static function validateForm($formName, &$fields, &$files, &$form, &$errors) {
423 return self::singleton()
424 ->invoke(5, $formName, $fields, $files, $form, $errors, self::$_nullObject, 'civicrm_validateForm');
425 }
426
427 /**
428 * This hook is called before a db write on a custom table
429 *
430 * @param string $op
431 * The type of operation being performed.
432 * @param string $groupID
433 * The custom group ID.
434 * @param object $entityID
435 * The entityID of the row in the custom table.
436 * @param array $params
437 * The parameters that were sent into the calling function.
438 *
439 * @return null
440 * the return value is ignored
441 */
442 public static function custom($op, $groupID, $entityID, &$params) {
443 return self::singleton()
444 ->invoke(4, $op, $groupID, $entityID, $params, self::$_nullObject, self::$_nullObject, 'civicrm_custom');
445 }
446
447 /**
448 * This hook is called when composing the ACL where clause to restrict
449 * visibility of contacts to the logged in user
450 *
451 * @param int $type
452 * The type of permission needed.
453 * @param array $tables
454 * (reference ) add the tables that are needed for the select clause.
455 * @param array $whereTables
456 * (reference ) add the tables that are needed for the where clause.
457 * @param int $contactID
458 * The contactID for whom the check is made.
459 * @param string $where
460 * The currrent where clause.
461 *
462 * @return null
463 * the return value is ignored
464 */
465 public static function aclWhereClause($type, &$tables, &$whereTables, &$contactID, &$where) {
466 return self::singleton()
467 ->invoke(5, $type, $tables, $whereTables, $contactID, $where, self::$_nullObject, 'civicrm_aclWhereClause');
468 }
469
470 /**
471 * This hook is called when composing the ACL where clause to restrict
472 * visibility of contacts to the logged in user
473 *
474 * @param int $type
475 * The type of permission needed.
476 * @param int $contactID
477 * The contactID for whom the check is made.
478 * @param string $tableName
479 * The tableName which is being permissioned.
480 * @param array $allGroups
481 * The set of all the objects for the above table.
482 * @param array $currentGroups
483 * The set of objects that are currently permissioned for this contact.
484 *
485 * @return null
486 * the return value is ignored
487 */
488 public static function aclGroup($type, $contactID, $tableName, &$allGroups, &$currentGroups) {
489 return self::singleton()
490 ->invoke(5, $type, $contactID, $tableName, $allGroups, $currentGroups, self::$_nullObject, 'civicrm_aclGroup');
491 }
492
493 /**
494 * This hook is called when building the menu table
495 *
496 * @param array $files
497 * The current set of files to process.
498 *
499 * @return null
500 * the return value is ignored
501 */
502 public static function xmlMenu(&$files) {
503 return self::singleton()->invoke(1, $files,
504 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
505 'civicrm_xmlMenu'
506 );
507 }
508
509 /**
510 * This hook is called for declaring managed entities via API
511 *
512 * @param array $entities
513 * List of pending entities.
514 *
515 * @return null
516 * the return value is ignored
517 */
518 public static function managed(&$entities) {
519 return self::singleton()->invoke(1, $entities,
520 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
521 'civicrm_managed'
522 );
523 }
524
525 /**
526 * This hook is called when rendering the dashboard (q=civicrm/dashboard)
527 *
528 * @param int $contactID
529 * The contactID for whom the dashboard is being rendered.
530 * @param int $contentPlacement
531 * (output parameter) where should the hook content be displayed.
532 * relative to the activity list
533 *
534 * @return string
535 * the html snippet to include in the dashboard
536 */
537 public static function dashboard($contactID, &$contentPlacement = self::DASHBOARD_BELOW) {
538 $retval = self::singleton()->invoke(2, $contactID, $contentPlacement,
539 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
540 'civicrm_dashboard'
541 );
542
543 /*
544 * Note we need this seemingly unnecessary code because in the event that the implementation
545 * of the hook declares the second parameter but doesn't set it, then it comes back unset even
546 * though we have a default value in this function's declaration above.
547 */
548 if (!isset($contentPlacement)) {
549 $contentPlacement = self::DASHBOARD_BELOW;
550 }
551
552 return $retval;
553 }
554
555 /**
556 * This hook is called before storing recently viewed items.
557 *
558 * @param array $recentArray
559 * An array of recently viewed or processed items, for in place modification.
560 *
561 * @return array
562 */
563 public static function recent(&$recentArray) {
564 return self::singleton()->invoke(1, $recentArray,
565 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
566 'civicrm_recent'
567 );
568 }
569
570 /**
571 * Determine how many other records refer to a given record
572 *
573 * @param CRM_Core_DAO $dao
574 * The item for which we want a reference count.
575 * @param array $refCounts
576 * Each item in the array is an array with keys:.
577 * - name: string, eg "sql:civicrm_email:contact_id"
578 * - type: string, eg "sql"
579 * - count: int, eg "5" if there are 5 email addresses that refer to $dao
580 * @return void
581 */
582 public static function referenceCounts($dao, &$refCounts) {
583 return self::singleton()->invoke(2, $dao, $refCounts,
584 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
585 'civicrm_referenceCounts'
586 );
587 }
588
589 /**
590 * This hook is called when building the amount structure for a Contribution or Event Page
591 *
592 * @param int $pageType
593 * Is this a contribution or event page.
594 * @param CRM_Core_Form $form
595 * Reference to the form object.
596 * @param array $amount
597 * The amount structure to be displayed.
598 *
599 * @return null
600 */
601 public static function buildAmount($pageType, &$form, &$amount) {
602 return self::singleton()->invoke(3, $pageType, $form, $amount, self::$_nullObject,
603 self::$_nullObject, self::$_nullObject, 'civicrm_buildAmount');
604 }
605
606 /**
607 * This hook is called when building the state list for a particular country.
608 *
609 * @param array $countryID
610 * The country id whose states are being selected.
611 * @param $states
612 *
613 * @return null
614 */
615 public static function buildStateProvinceForCountry($countryID, &$states) {
616 return self::singleton()->invoke(2, $countryID, $states,
617 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
618 'civicrm_buildStateProvinceForCountry'
619 );
620 }
621
622 /**
623 * This hook is called when rendering the tabs for a contact (q=civicrm/contact/view)c
624 *
625 * @param array $tabs
626 * The array of tabs that will be displayed.
627 * @param int $contactID
628 * The contactID for whom the dashboard is being rendered.
629 *
630 * @return null
631 */
632 public static function tabs(&$tabs, $contactID) {
633 return self::singleton()->invoke(2, $tabs, $contactID,
634 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_tabs'
635 );
636 }
637
638 /**
639 * This hook is called when rendering the tabs used for events and potentially
640 * contribution pages, etc.
641 *
642 * @param string $tabsetName
643 * Name of the screen or visual element.
644 * @param array $tabs
645 * Tabs that will be displayed.
646 * @param array $context
647 * Extra data about the screen or context in which the tab is used.
648 *
649 * @return null
650 */
651 public static function tabset($tabsetName, &$tabs, $context) {
652 return self::singleton()->invoke(3, $tabsetName, $tabs,
653 $context, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_tabset'
654 );
655 }
656
657 /**
658 * This hook is called when sending an email / printing labels
659 *
660 * @param array $tokens
661 * The list of tokens that can be used for the contact.
662 *
663 * @return null
664 */
665 public static function tokens(&$tokens) {
666 return self::singleton()->invoke(1, $tokens,
667 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_tokens'
668 );
669 }
670
671 /**
672 * This hook is called when sending an email / printing labels to get the values for all the
673 * tokens returned by the 'tokens' hook
674 *
675 * @param array $details
676 * The array to store the token values indexed by contactIDs (unless it a single).
677 * @param array $contactIDs
678 * An array of contactIDs.
679 * @param int $jobID
680 * The jobID if this is associated with a CiviMail mailing.
681 * @param array $tokens
682 * The list of tokens associated with the content.
683 * @param string $className
684 * The top level className from where the hook is invoked.
685 *
686 * @return null
687 */
688 public static function tokenValues(
689 &$details,
690 $contactIDs,
691 $jobID = NULL,
692 $tokens = array(),
693 $className = NULL
694 ) {
695 return self::singleton()
696 ->invoke(5, $details, $contactIDs, $jobID, $tokens, $className, self::$_nullObject, 'civicrm_tokenValues');
697 }
698
699 /**
700 * This hook is called before a CiviCRM Page is rendered. You can use this hook to insert smarty variables
701 * in a template
702 *
703 * @param object $page
704 * The page that will be rendered.
705 *
706 * @return null
707 */
708 public static function pageRun(&$page) {
709 return self::singleton()->invoke(1, $page,
710 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
711 'civicrm_pageRun'
712 );
713 }
714
715 /**
716 * This hook is called after a copy of an object has been made. The current objects are
717 * Event, Contribution Page and UFGroup
718 *
719 * @param string $objectName
720 * Name of the object.
721 * @param object $object
722 * Reference to the copy.
723 *
724 * @return null
725 */
726 public static function copy($objectName, &$object) {
727 return self::singleton()->invoke(2, $objectName, $object,
728 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
729 'civicrm_copy'
730 );
731 }
732
733 /**
734 * This hook is called when a contact unsubscribes from a mailing. It allows modules
735 * to override what the contacts are removed from.
736 *
737 * @param string $op
738 * Ignored for now
739 * @param int $mailingId
740 * The id of the mailing to unsub from
741 * @param int $contactId
742 * The id of the contact who is unsubscribing
743 * @param array|int $groups
744 * Groups the contact will be removed from.
745 * @param array|int $baseGroups
746 * Base groups (used in smart mailings) the contact will be removed from.
747 *
748 *
749 * @return mixed
750 */
751 public static function unsubscribeGroups($op, $mailingId, $contactId, &$groups, &$baseGroups) {
752 return self::singleton()
753 ->invoke(5, $op, $mailingId, $contactId, $groups, $baseGroups, self::$_nullObject, 'civicrm_unsubscribeGroups');
754 }
755
756 /**
757 * This hook is called when CiviCRM needs to edit/display a custom field with options (select, radio, checkbox,
758 * adv multiselect)
759 *
760 * @param int $customFieldID
761 * The custom field ID.
762 * @param array $options
763 * The current set of options for that custom field.
764 * You can add/remove existing options.
765 * Important: This array may contain meta-data about the field that is needed elsewhere, so it is important
766 * to be careful to not overwrite the array.
767 * Only add/edit/remove the specific field options you intend to affect.
768 * @param bool $detailedFormat
769 * If true,.
770 * the options are in an ID => array ( 'id' => ID, 'label' => label, 'value' => value ) format
771 * @param array $selectAttributes
772 * Contain select attribute(s) if any.
773 *
774 * @return mixed
775 */
776 public static function customFieldOptions($customFieldID, &$options, $detailedFormat = FALSE, $selectAttributes = array()) {
777 return self::singleton()->invoke(3, $customFieldID, $options, $detailedFormat,
778 self::$_nullObject, self::$_nullObject, self::$_nullObject,
779 'civicrm_customFieldOptions'
780 );
781 }
782
783 /**
784 *
785 * This hook is called to display the list of actions allowed after doing a search.
786 * This allows the module developer to inject additional actions or to remove existing actions.
787 *
788 * @param string $objectType
789 * The object type for this search.
790 * - activity, campaign, case, contact, contribution, event, grant, membership, and pledge are supported.
791 * @param array $tasks
792 * The current set of tasks for that custom field.
793 * You can add/remove existing tasks.
794 * Each task needs to have a title (eg 'title' => ts( 'Add Contacts to Group')) and a class
795 * (eg 'class' => 'CRM_Contact_Form_Task_AddToGroup').
796 * Optional result (boolean) may also be provided. Class can be an array of classes (not sure what that does :( ).
797 * The key for new Task(s) should not conflict with the keys for core tasks of that $objectType, which can be
798 * found in CRM/$objectType/Task.php.
799 *
800 * @return mixed
801 */
802 public static function searchTasks($objectType, &$tasks) {
803 return self::singleton()->invoke(2, $objectType, $tasks,
804 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
805 'civicrm_searchTasks'
806 );
807 }
808
809 /**
810 * @param mixed $form
811 * @param array $params
812 *
813 * @return mixed
814 */
815 public static function eventDiscount(&$form, &$params) {
816 return self::singleton()->invoke(2, $form, $params,
817 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
818 'civicrm_eventDiscount'
819 );
820 }
821
822 /**
823 * This hook is called when composing a mailing. You can include / exclude other groups as needed.
824 *
825 * @param mixed $form
826 * The form object for which groups / mailings being displayed
827 * @param array $groups
828 * The list of groups being included / excluded
829 * @param array $mailings
830 * The list of mailings being included / excluded
831 *
832 * @return mixed
833 */
834 public static function mailingGroups(&$form, &$groups, &$mailings) {
835 return self::singleton()->invoke(3, $form, $groups, $mailings,
836 self::$_nullObject, self::$_nullObject, self::$_nullObject,
837 'civicrm_mailingGroups'
838 );
839 }
840
841 /**
842 * This hook is called when composing the array of membershipTypes and their cost during a membership registration
843 * (new or renewal).
844 * Note the hook is called on initial page load and also reloaded after submit (PRG pattern).
845 * You can use it to alter the membership types when first loaded, or after submission
846 * (for example if you want to gather data in the form and use it to alter the fees).
847 *
848 * @param mixed $form
849 * The form object that is presenting the page
850 * @param array $membershipTypes
851 * The array of membership types and their amount
852 *
853 * @return mixed
854 */
855 public static function membershipTypeValues(&$form, &$membershipTypes) {
856 return self::singleton()->invoke(2, $form, $membershipTypes,
857 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
858 'civicrm_membershipTypeValues'
859 );
860 }
861
862 /**
863 * This hook is called when rendering the contact summary
864 *
865 * @param int $contactID
866 * The contactID for whom the summary is being rendered
867 * @param mixed $content
868 * @param int $contentPlacement
869 * Specifies where the hook content should be displayed relative to the
870 * existing content
871 *
872 * @return string
873 * The html snippet to include in the contact summary
874 */
875 public static function summary($contactID, &$content, &$contentPlacement = self::SUMMARY_BELOW) {
876 return self::singleton()->invoke(3, $contactID, $content, $contentPlacement,
877 self::$_nullObject, self::$_nullObject, self::$_nullObject,
878 'civicrm_summary'
879 );
880 }
881
882 /**
883 * Use this hook to populate the list of contacts returned by Contact Reference custom fields.
884 * By default, Contact Reference fields will search on and return all CiviCRM contacts.
885 * If you want to limit the contacts returned to a specific group, or some other criteria
886 * - you can override that behavior by providing a SQL query that returns some subset of your contacts.
887 * The hook is called when the query is executed to get the list of contacts to display.
888 *
889 * @param mixed $query
890 * - the query that will be executed (input and output parameter);.
891 * It's important to realize that the ACL clause is built prior to this hook being fired,
892 * so your query will ignore any ACL rules that may be defined.
893 * Your query must return two columns:
894 * the contact 'data' to display in the autocomplete dropdown (usually contact.sort_name - aliased as 'data')
895 * the contact IDs
896 * @param string $name
897 * The name string to execute the query against (this is the value being typed in by the user).
898 * @param string $context
899 * The context in which this ajax call is being made (for example: 'customfield', 'caseview').
900 * @param int $id
901 * The id of the object for which the call is being made.
902 * For custom fields, it will be the custom field id
903 *
904 * @return mixed
905 */
906 public static function contactListQuery(&$query, $name, $context, $id) {
907 return self::singleton()->invoke(4, $query, $name, $context, $id,
908 self::$_nullObject, self::$_nullObject,
909 'civicrm_contactListQuery'
910 );
911 }
912
913 /**
914 * Hook definition for altering payment parameters before talking to a payment processor back end.
915 *
916 * Definition will look like this:
917 *
918 * function hook_civicrm_alterPaymentProcessorParams($paymentObj,
919 * &$rawParams, &$cookedParams);
920 *
921 * @param string $paymentObj
922 * instance of payment class of the payment processor invoked (e.g., 'CRM_Core_Payment_Dummy')
923 * @param array &$rawParams
924 * array of params as passed to to the processor
925 * @param array &$cookedParams
926 * params after the processor code has translated them into its own key/value pairs
927 *
928 * @return mixed
929 */
930 public static function alterPaymentProcessorParams(
931 $paymentObj,
932 &$rawParams,
933 &$cookedParams
934 ) {
935 return self::singleton()->invoke(3, $paymentObj, $rawParams, $cookedParams,
936 self::$_nullObject, self::$_nullObject, self::$_nullObject,
937 'civicrm_alterPaymentProcessorParams'
938 );
939 }
940
941 /**
942 * This hook is called when an email is about to be sent by CiviCRM.
943 *
944 * @param array $params
945 * Array fields include: groupName, from, toName, toEmail, subject, cc, bcc, text, html,
946 * returnPath, replyTo, headers, attachments (array)
947 * @param string $context
948 * The context in which the hook is being invoked, eg 'civimail'.
949 *
950 * @return mixed
951 */
952 public static function alterMailParams(&$params, $context = NULL) {
953 return self::singleton()->invoke(2, $params, $context,
954 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
955 'civicrm_alterMailParams'
956 );
957 }
958
959 /**
960 * This hook is called when membership status is being calculated
961 *
962 * @param array $membershipStatus
963 * Membership status details as determined - alter if required.
964 * @param array $arguments
965 * Arguments passed in to calculate date.
966 * - 'start_date'
967 * - 'end_date'
968 * - 'status_date'
969 * - 'join_date'
970 * - 'exclude_is_admin'
971 * - 'membership_type_id'
972 * @param array $membership
973 * Membership details from the calling function.
974 *
975 * @return mixed
976 */
977 public static function alterCalculatedMembershipStatus(&$membershipStatus, $arguments, $membership) {
978 return self::singleton()->invoke(3, $membershipStatus, $arguments,
979 $membership, self::$_nullObject, self::$_nullObject, self::$_nullObject,
980 'civicrm_alterCalculatedMembershipStatus'
981 );
982 }
983
984 /**
985 * This hook is called when rendering the Manage Case screen
986 *
987 * @param int $caseID
988 * The case ID.
989 *
990 * @return array
991 * of data to be displayed, where the key is a unique id to be used for styling (div id's)
992 * and the value is an array with keys 'label' and 'value' specifying label/value pairs
993 */
994 public static function caseSummary($caseID) {
995 return self::singleton()->invoke(1, $caseID,
996 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
997 'civicrm_caseSummary'
998 );
999 }
1000
1001 /**
1002 * This hook is called when locating CiviCase types.
1003 *
1004 * @param array $caseTypes
1005 *
1006 * @return mixed
1007 */
1008 public static function caseTypes(&$caseTypes) {
1009 return self::singleton()
1010 ->invoke(1, $caseTypes, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_caseTypes');
1011 }
1012
1013 /**
1014 * This hook is called soon after the CRM_Core_Config object has ben initialized.
1015 * You can use this hook to modify the config object and hence behavior of CiviCRM dynamically.
1016 *
1017 * @param CRM_Core_Config|array $config
1018 * The config object
1019 *
1020 * @return mixed
1021 */
1022 public static function config(&$config) {
1023 return self::singleton()->invoke(1, $config,
1024 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
1025 'civicrm_config'
1026 );
1027 }
1028
1029 /**
1030 * @param $recordBAO
1031 * @param int $recordID
1032 * @param $isActive
1033 *
1034 * @return mixed
1035 */
1036 public static function enableDisable($recordBAO, $recordID, $isActive) {
1037 return self::singleton()->invoke(3, $recordBAO, $recordID, $isActive,
1038 self::$_nullObject, self::$_nullObject, self::$_nullObject,
1039 'civicrm_enableDisable'
1040 );
1041 }
1042
1043 /**
1044 * This hooks allows to change option values
1045 *
1046 * @param array $options
1047 * Associated array of option values / id
1048 * @param string $name
1049 * Option group name
1050 *
1051 * @return mixed
1052 */
1053 public static function optionValues(&$options, $name) {
1054 return self::singleton()->invoke(2, $options, $name,
1055 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
1056 'civicrm_optionValues'
1057 );
1058 }
1059
1060 /**
1061 * This hook allows modification of the navigation menu.
1062 *
1063 * @param array $params
1064 * Associated array of navigation menu entry to Modify/Add
1065 *
1066 * @return mixed
1067 */
1068 public static function navigationMenu(&$params) {
1069 return self::singleton()->invoke(1, $params,
1070 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
1071 'civicrm_navigationMenu'
1072 );
1073 }
1074
1075 /**
1076 * This hook allows modification of the data used to perform merging of duplicates.
1077 *
1078 * @param string $type
1079 * The type of data being passed (cidRefs|eidRefs|relTables|sqls).
1080 * @param array $data
1081 * The data, as described in $type.
1082 * @param int $mainId
1083 * Contact_id of the contact that survives the merge.
1084 * @param int $otherId
1085 * Contact_id of the contact that will be absorbed and deleted.
1086 * @param array $tables
1087 * When $type is "sqls", an array of tables as it may have been handed to the calling function.
1088 *
1089 * @return mixed
1090 */
1091 public static function merge($type, &$data, $mainId = NULL, $otherId = NULL, $tables = NULL) {
1092 return self::singleton()->invoke(5, $type, $data, $mainId, $otherId, $tables, self::$_nullObject, 'civicrm_merge');
1093 }
1094
1095 /**
1096 * This hook provides a way to override the default privacy behavior for notes.
1097 *
1098 * @param array &$noteValues
1099 * Associative array of values for this note
1100 *
1101 * @return mixed
1102 */
1103 public static function notePrivacy(&$noteValues) {
1104 return self::singleton()->invoke(1, $noteValues,
1105 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
1106 'civicrm_notePrivacy'
1107 );
1108 }
1109
1110 /**
1111 * This hook is called before record is exported as CSV
1112 *
1113 * @param string $exportTempTable
1114 * Name of the temporary export table used during export.
1115 * @param array $headerRows
1116 * Header rows for output.
1117 * @param array $sqlColumns
1118 * SQL columns.
1119 * @param int $exportMode
1120 * Export mode ( contact, contribution, etc...).
1121 *
1122 * @return mixed
1123 */
1124 public static function export(&$exportTempTable, &$headerRows, &$sqlColumns, &$exportMode) {
1125 return self::singleton()->invoke(4, $exportTempTable, $headerRows, $sqlColumns, $exportMode,
1126 self::$_nullObject, self::$_nullObject,
1127 'civicrm_export'
1128 );
1129 }
1130
1131 /**
1132 * This hook allows modification of the queries constructed from dupe rules.
1133 *
1134 * @param string $obj
1135 * Object of rulegroup class.
1136 * @param string $type
1137 * Type of queries e.g table / threshold.
1138 * @param array $query
1139 * Set of queries.
1140 *
1141 * @return mixed
1142 */
1143 public static function dupeQuery($obj, $type, &$query) {
1144 return self::singleton()->invoke(3, $obj, $type, $query,
1145 self::$_nullObject, self::$_nullObject, self::$_nullObject,
1146 'civicrm_dupeQuery'
1147 );
1148 }
1149
1150 /**
1151 * This hook is called AFTER EACH email has been processed by the script bin/EmailProcessor.php
1152 *
1153 * @param string $type
1154 * Type of mail processed: 'activity' OR 'mailing'.
1155 * @param array &$params the params that were sent to the CiviCRM API function
1156 * @param object $mail
1157 * The mail object which is an ezcMail class.
1158 * @param array &$result the result returned by the api call
1159 * @param string $action
1160 * (optional ) the requested action to be performed if the types was 'mailing'.
1161 *
1162 * @return mixed
1163 */
1164 public static function emailProcessor($type, &$params, $mail, &$result, $action = NULL) {
1165 return self::singleton()
1166 ->invoke(5, $type, $params, $mail, $result, $action, self::$_nullObject, 'civicrm_emailProcessor');
1167 }
1168
1169 /**
1170 * This hook is called after a row has been processed and the
1171 * record (and associated records imported
1172 *
1173 * @param string $object
1174 * Object being imported (for now Contact only, later Contribution, Activity,.
1175 * Participant and Member)
1176 * @param string $usage
1177 * Hook usage/location (for now process only, later mapping and others).
1178 * @param string $objectRef
1179 * Import record object.
1180 * @param array $params
1181 * Array with various key values: currently.
1182 * contactID - contact id
1183 * importID - row id in temp table
1184 * importTempTable - name of tempTable
1185 * fieldHeaders - field headers
1186 * fields - import fields
1187 *
1188 * @return void
1189 */
1190 public static function import($object, $usage, &$objectRef, &$params) {
1191 return self::singleton()->invoke(4, $object, $usage, $objectRef, $params,
1192 self::$_nullObject, self::$_nullObject,
1193 'civicrm_import'
1194 );
1195 }
1196
1197 /**
1198 * This hook is called when API permissions are checked (cf. civicrm_api3_api_check_permission()
1199 * in api/v3/utils.php and _civicrm_api3_permissions() in CRM/Core/DAO/permissions.php).
1200 *
1201 * @param string $entity
1202 * The API entity (like contact).
1203 * @param string $action
1204 * The API action (like get).
1205 * @param array &$params the API parameters
1206 * @param array &$permissions the associative permissions array (probably to be altered by this hook)
1207 *
1208 * @return mixed
1209 */
1210 public static function alterAPIPermissions($entity, $action, &$params, &$permissions) {
1211 return self::singleton()->invoke(4, $entity, $action, $params, $permissions,
1212 self::$_nullObject, self::$_nullObject,
1213 'civicrm_alterAPIPermissions'
1214 );
1215 }
1216
1217 /**
1218 * @param CRM_Core_DAO $dao
1219 *
1220 * @return mixed
1221 */
1222 public static function postSave(&$dao) {
1223 $hookName = 'civicrm_postSave_' . $dao->getTableName();
1224 return self::singleton()->invoke(1, $dao,
1225 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
1226 $hookName
1227 );
1228 }
1229
1230 /**
1231 * This hook allows user to customize context menu Actions on contact summary page.
1232 *
1233 * @param array $actions
1234 * Array of all Actions in contextmenu.
1235 * @param int $contactID
1236 * ContactID for the summary page.
1237 *
1238 * @return mixed
1239 */
1240 public static function summaryActions(&$actions, $contactID = NULL) {
1241 return self::singleton()->invoke(2, $actions, $contactID,
1242 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
1243 'civicrm_summaryActions'
1244 );
1245 }
1246
1247 /**
1248 * This hook is called from CRM_Core_Selector_Controller through which all searches in civicrm go.
1249 * This enables us hook implementors to modify both the headers and the rows
1250 *
1251 * The BIGGEST drawback with this hook is that you may need to modify the result template to include your
1252 * fields. The result files are CRM/{Contact,Contribute,Member,Event...}/Form/Selector.tpl
1253 *
1254 * However, if you use the same number of columns, you can overwrite the existing columns with the values that
1255 * you want displayed. This is a hackish, but avoids template modification.
1256 *
1257 * @param string $objectName
1258 * The component name that we are doing the search.
1259 * activity, campaign, case, contact, contribution, event, grant, membership, and pledge
1260 * @param array &$headers the list of column headers, an associative array with keys: ( name, sort, order )
1261 * @param array &$rows the list of values, an associate array with fields that are displayed for that component
1262 * @param $selector
1263 *
1264 * @internal param array $seletor the selector object. Allows you access to the context of the search
1265 *
1266 * @return void
1267 * modify the header and values object to pass the data u need
1268 */
1269 public static function searchColumns($objectName, &$headers, &$rows, &$selector) {
1270 return self::singleton()->invoke(4, $objectName, $headers, $rows, $selector,
1271 self::$_nullObject, self::$_nullObject,
1272 'civicrm_searchColumns'
1273 );
1274 }
1275
1276 /**
1277 * This hook is called when uf groups are being built for a module.
1278 *
1279 * @param string $moduleName
1280 * Module name.
1281 * @param array $ufGroups
1282 * Array of ufgroups for a module.
1283 *
1284 * @return null
1285 */
1286 public static function buildUFGroupsForModule($moduleName, &$ufGroups) {
1287 return self::singleton()->invoke(2, $moduleName, $ufGroups,
1288 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
1289 'civicrm_buildUFGroupsForModule'
1290 );
1291 }
1292
1293 /**
1294 * This hook is called when we are determining the contactID for a specific
1295 * email address
1296 *
1297 * @param string $email
1298 * The email address.
1299 * @param int $contactID
1300 * The contactID that matches this email address, IF it exists.
1301 * @param array $result
1302 * (reference) has two fields.
1303 * contactID - the new (or same) contactID
1304 * action - 3 possible values:
1305 * CRM_Utils_Mail_Incoming::EMAILPROCESSOR_CREATE_INDIVIDUAL - create a new contact record
1306 * CRM_Utils_Mail_Incoming::EMAILPROCESSOR_OVERRIDE - use the new contactID
1307 * CRM_Utils_Mail_Incoming::EMAILPROCESSOR_IGNORE - skip this email address
1308 *
1309 * @return null
1310 */
1311 public static function emailProcessorContact($email, $contactID, &$result) {
1312 return self::singleton()->invoke(3, $email, $contactID, $result,
1313 self::$_nullObject, self::$_nullObject, self::$_nullObject,
1314 'civicrm_emailProcessorContact'
1315 );
1316 }
1317
1318 /**
1319 * Hook definition for altering the generation of Mailing Labels
1320 *
1321 * @param array $args
1322 * An array of the args in the order defined for the tcpdf multiCell api call.
1323 * with the variable names below converted into string keys (ie $w become 'w'
1324 * as the first key for $args)
1325 * float $w Width of cells. If 0, they extend up to the right margin of the page.
1326 * float $h Cell minimum height. The cell extends automatically if needed.
1327 * string $txt String to print
1328 * mixed $border Indicates if borders must be drawn around the cell block. The value can
1329 * be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or
1330 * a string containing some or all of the following characters (in any order):
1331 * <ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul>
1332 * string $align Allows to center or align the text. Possible values are:<ul><li>L or empty string:
1333 * left align</li><li>C: center</li><li>R: right align</li><li>J: justification
1334 * (default value when $ishtml=false)</li></ul>
1335 * int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
1336 * int $ln Indicates where the current position should go after the call. Possible values are:<ul><li>0:
1337 * to the right</li><li>1: to the beginning of the next line [DEFAULT]</li><li>2: below</li></ul>
1338 * float $x x position in user units
1339 * float $y y position in user units
1340 * boolean $reseth if true reset the last cell height (default true).
1341 * int $stretch stretch carachter mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if
1342 * necessary</li><li>2 = forced horizontal scaling</li><li>3 = character spacing only if
1343 * necessary</li><li>4 = forced character spacing</li></ul>
1344 * boolean $ishtml set to true if $txt is HTML content (default = false).
1345 * boolean $autopadding if true, uses internal padding and automatically adjust it to account for line width.
1346 * float $maxh maximum height. It should be >= $h and less then remaining space to the bottom of the page,
1347 * or 0 for disable this feature. This feature works only when $ishtml=false.
1348 *
1349 * @return mixed
1350 */
1351 public static function alterMailingLabelParams(&$args) {
1352 return self::singleton()->invoke(1, $args,
1353 self::$_nullObject, self::$_nullObject,
1354 self::$_nullObject, self::$_nullObject, self::$_nullObject,
1355 'civicrm_alterMailingLabelParams'
1356 );
1357 }
1358
1359 /**
1360 * This hooks allows alteration of generated page content
1361 *
1362 * @param $content
1363 * Previously generated content.
1364 * @param $context
1365 * Context of content - page or form.
1366 * @param $tplName
1367 * The file name of the tpl.
1368 * @param $object
1369 * A reference to the page or form object.
1370 *
1371 * @return mixed
1372 */
1373 public static function alterContent(&$content, $context, $tplName, &$object) {
1374 return self::singleton()->invoke(4, $content, $context, $tplName, $object,
1375 self::$_nullObject, self::$_nullObject,
1376 'civicrm_alterContent'
1377 );
1378 }
1379
1380 /**
1381 * This hooks allows alteration of the tpl file used to generate content. It differs from the
1382 * altercontent hook as the content has already been rendered through the tpl at that point
1383 *
1384 * @param $formName
1385 * Previously generated content.
1386 * @param $form
1387 * Reference to the form object.
1388 * @param $context
1389 * Context of content - page or form.
1390 * @param $tplName
1391 * Reference the file name of the tpl.
1392 *
1393 * @return mixed
1394 */
1395 public static function alterTemplateFile($formName, &$form, $context, &$tplName) {
1396 return self::singleton()->invoke(4, $formName, $form, $context, $tplName,
1397 self::$_nullObject, self::$_nullObject,
1398 'civicrm_alterTemplateFile'
1399 );
1400 }
1401
1402 /**
1403 * This hook collects the trigger definition from all components
1404 *
1405 * @param $info
1406 * @param string $tableName
1407 * (optional) the name of the table that we are interested in only.
1408 *
1409 * @internal param \reference $triggerInfo to an array of trigger information
1410 * each element has 4 fields:
1411 * table - array of tableName
1412 * when - BEFORE or AFTER
1413 * event - array of eventName - INSERT OR UPDATE OR DELETE
1414 * sql - array of statements optionally terminated with a ;
1415 * a statement can use the tokes {tableName} and {eventName}
1416 * to do token replacement with the table / event. This allows
1417 * templatizing logging and other hooks
1418 * @return mixed
1419 */
1420 public static function triggerInfo(&$info, $tableName = NULL) {
1421 return self::singleton()->invoke(2, $info, $tableName,
1422 self::$_nullObject, self::$_nullObject, self::$_nullObject,
1423 self::$_nullObject,
1424 'civicrm_triggerInfo'
1425 );
1426 }
1427
1428 /**
1429 * This hook is called when a module-extension is installed.
1430 * Each module will receive hook_civicrm_install during its own installation (but not during the
1431 * installation of unrelated modules).
1432 */
1433 public static function install() {
1434 return self::singleton()->invoke(0, self::$_nullObject,
1435 self::$_nullObject, self::$_nullObject,
1436 self::$_nullObject, self::$_nullObject, self::$_nullObject,
1437 'civicrm_install'
1438 );
1439 }
1440
1441 /**
1442 * This hook is called when a module-extension is uninstalled.
1443 * Each module will receive hook_civicrm_uninstall during its own uninstallation (but not during the
1444 * uninstallation of unrelated modules).
1445 */
1446 public static function uninstall() {
1447 return self::singleton()->invoke(0, self::$_nullObject,
1448 self::$_nullObject, self::$_nullObject,
1449 self::$_nullObject, self::$_nullObject, self::$_nullObject,
1450 'civicrm_uninstall'
1451 );
1452 }
1453
1454 /**
1455 * This hook is called when a module-extension is re-enabled.
1456 * Each module will receive hook_civicrm_enable during its own re-enablement (but not during the
1457 * re-enablement of unrelated modules).
1458 */
1459 public static function enable() {
1460 return self::singleton()->invoke(0, self::$_nullObject,
1461 self::$_nullObject, self::$_nullObject,
1462 self::$_nullObject, self::$_nullObject, self::$_nullObject,
1463 'civicrm_enable'
1464 );
1465 }
1466
1467 /**
1468 * This hook is called when a module-extension is disabled.
1469 * Each module will receive hook_civicrm_disable during its own disablement (but not during the
1470 * disablement of unrelated modules).
1471 */
1472 public static function disable() {
1473 return self::singleton()->invoke(0, self::$_nullObject,
1474 self::$_nullObject, self::$_nullObject,
1475 self::$_nullObject, self::$_nullObject, self::$_nullObject,
1476 'civicrm_disable'
1477 );
1478 }
1479
1480 /**
1481 * @param $varType
1482 * @param $var
1483 * @param $object
1484 *
1485 * @return mixed
1486 */
1487 public static function alterReportVar($varType, &$var, &$object) {
1488 return self::singleton()->invoke(3, $varType, $var, $object,
1489 self::$_nullObject,
1490 self::$_nullObject, self::$_nullObject,
1491 'civicrm_alterReportVar'
1492 );
1493 }
1494
1495 /**
1496 * This hook is called to drive database upgrades for extension-modules.
1497 *
1498 * @param string $op
1499 * The type of operation being performed; 'check' or 'enqueue'.
1500 * @param CRM_Queue_Queue $queue
1501 * (for 'enqueue') the modifiable list of pending up upgrade tasks.
1502 *
1503 * @return bool|null
1504 * NULL, if $op is 'enqueue'.
1505 * TRUE, if $op is 'check' and upgrades are pending.
1506 * FALSE, if $op is 'check' and upgrades are not pending.
1507 */
1508 public static function upgrade($op, CRM_Queue_Queue $queue = NULL) {
1509 return self::singleton()->invoke(2, $op, $queue,
1510 self::$_nullObject, self::$_nullObject, self::$_nullObject,
1511 self::$_nullObject,
1512 'civicrm_upgrade'
1513 );
1514 }
1515
1516 /**
1517 * This hook is called when an email has been successfully sent by CiviCRM, but not on an error.
1518 *
1519 * @param array $params
1520 * The mailing parameters. Array fields include: groupName, from, toName,
1521 * toEmail, subject, cc, bcc, text, html, returnPath, replyTo, headers,
1522 * attachments (array)
1523 *
1524 * @return mixed
1525 */
1526 public static function postEmailSend(&$params) {
1527 return self::singleton()->invoke(1, $params,
1528 self::$_nullObject, self::$_nullObject,
1529 self::$_nullObject, self::$_nullObject, self::$_nullObject,
1530 'civicrm_postEmailSend'
1531 );
1532 }
1533
1534 /**
1535 * This hook is called when Settings specifications are loaded
1536 *
1537 * @param array $settingsFolders
1538 * List of paths from which to derive metadata
1539 *
1540 * @return mixed
1541 */
1542 public static function alterSettingsFolders(&$settingsFolders) {
1543 return self::singleton()->invoke(1, $settingsFolders,
1544 self::$_nullObject, self::$_nullObject,
1545 self::$_nullObject, self::$_nullObject, self::$_nullObject,
1546 'civicrm_alterSettingsFolders'
1547 );
1548 }
1549
1550 /**
1551 * This hook is called when Settings have been loaded from the xml
1552 * It is an opportunity for hooks to alter the data
1553 *
1554 * @param array $settingsMetaData
1555 * Settings Metadata.
1556 * @param int $domainID
1557 * @param mixed $profile
1558 *
1559 * @return mixed
1560 */
1561 public static function alterSettingsMetaData(&$settingsMetaData, $domainID, $profile) {
1562 return self::singleton()->invoke(3, $settingsMetaData,
1563 $domainID, $profile,
1564 self::$_nullObject, self::$_nullObject, self::$_nullObject,
1565 'civicrm_alterSettingsMetaData'
1566 );
1567 }
1568
1569 /**
1570 * This hook is called before running an api call.
1571 *
1572 * @param API_Wrapper[] $wrappers
1573 * (see CRM_Utils_API_ReloadOption as an example)
1574 * @param mixed $apiRequest
1575 *
1576 * @return null
1577 * The return value is ignored
1578 */
1579 public static function apiWrappers(&$wrappers, $apiRequest) {
1580 return self::singleton()
1581 ->invoke(2, $wrappers, $apiRequest, self::$_nullObject, self::$_nullObject, self::$_nullObject,
1582 self::$_nullObject, 'civicrm_apiWrappers'
1583 );
1584 }
1585
1586 /**
1587 * This hook is called before running pending cron jobs.
1588 *
1589 * @param CRM_Core_JobManager $jobManager
1590 *
1591 * @return null
1592 * The return value is ignored.
1593 */
1594 public static function cron($jobManager) {
1595 return self::singleton()->invoke(1,
1596 $jobManager, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
1597 'civicrm_cron'
1598 );
1599 }
1600
1601 /**
1602 * This hook is called when loading CMS permissions; use this hook to modify
1603 * the array of system permissions for CiviCRM.
1604 *
1605 * @param array $permissions
1606 * Array of permissions. See CRM_Core_Permission::getCorePermissions() for
1607 * the format of this array.
1608 *
1609 * @return null
1610 * The return value is ignored
1611 */
1612 public static function permission(&$permissions) {
1613 return self::singleton()->invoke(1, $permissions,
1614 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
1615 'civicrm_permission'
1616 );
1617 }
1618
1619 /**
1620 * @param CRM_Core_Exception Exception $exception
1621 * @param mixed $request
1622 * Reserved for future use.
1623 */
1624 public static function unhandledException($exception, $request = NULL) {
1625 self::singleton()
1626 ->invoke(2, $exception, $request, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_unhandled_exception');
1627 // == 4.4 ==
1628 //$event = new stdClass();
1629 //$event->exception = $exception;
1630 //CRM_Core_LegacyErrorHandler::handleException($event);
1631
1632 // == 4.5+ ==
1633 $event = new \Civi\Core\Event\UnhandledExceptionEvent($exception, self::$_nullObject);
1634 \Civi\Core\Container::singleton()->get('dispatcher')->dispatch("hook_civicrm_unhandled_exception", $event);
1635 }
1636
1637 /**
1638 * This hook is called for declaring managed entities via API
1639 *
1640 * @param array[] $entityTypes
1641 * List of entity types; each entity-type is an array with keys:
1642 * - name: string, a unique short name (e.g. "ReportInstance")
1643 * - class: string, a PHP DAO class (e.g. "CRM_Report_DAO_Instance")
1644 * - table: string, a SQL table name (e.g. "civicrm_report_instance")
1645 *
1646 * @return null
1647 * The return value is ignored
1648 */
1649 public static function entityTypes(&$entityTypes) {
1650 return self::singleton()->invoke(1, $entityTypes, self::$_nullObject, self::$_nullObject,
1651 self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_entityTypes'
1652 );
1653 }
1654
1655 /**
1656 * This hook is called while preparing a profile form
1657 *
1658 * @param string $name
1659 * @return mixed
1660 */
1661 public static function buildProfile($name) {
1662 return self::singleton()->invoke(1, $name, self::$_nullObject, self::$_nullObject, self::$_nullObject,
1663 self::$_nullObject, self::$_nullObject, 'civicrm_buildProfile');
1664 }
1665
1666 /**
1667 * This hook is called while validating a profile form submission
1668 *
1669 * @param string $name
1670 * @return mixed
1671 */
1672 public static function validateProfile($name) {
1673 return self::singleton()->invoke(1, $name, self::$_nullObject, self::$_nullObject, self::$_nullObject,
1674 self::$_nullObject, self::$_nullObject, 'civicrm_validateProfile');
1675 }
1676
1677 /**
1678 * This hook is called processing a valid profile form submission
1679 *
1680 * @param string $name
1681 * @return mixed
1682 */
1683 public static function processProfile($name) {
1684 return self::singleton()->invoke(1, $name, self::$_nullObject, self::$_nullObject, self::$_nullObject,
1685 self::$_nullObject, self::$_nullObject, 'civicrm_processProfile');
1686 }
1687
1688 /**
1689 * This hook is called while preparing a read-only profile screen
1690 *
1691 * @param string $name
1692 * @return mixed
1693 */
1694 public static function viewProfile($name) {
1695 return self::singleton()->invoke(1, $name, self::$_nullObject, self::$_nullObject, self::$_nullObject,
1696 self::$_nullObject, self::$_nullObject, 'civicrm_viewProfile');
1697 }
1698
1699 /**
1700 * This hook is called while preparing a list of contacts (based on a profile)
1701 *
1702 * @param string $name
1703 * @return mixed
1704 */
1705 public static function searchProfile($name) {
1706 return self::singleton()->invoke(1, $name, self::$_nullObject, self::$_nullObject, self::$_nullObject,
1707 self::$_nullObject, self::$_nullObject, 'civicrm_searchProfile');
1708 }
1709
1710 /**
1711 * This hook is invoked when building a CiviCRM name badge.
1712 *
1713 * @param string $labelName
1714 * String referencing name of badge format.
1715 * @param object $label
1716 * Reference to the label object.
1717 * @param array $format
1718 * Array of format data.
1719 * @param array $participant
1720 * Array of participant values.
1721 *
1722 * @return null
1723 * the return value is ignored
1724 */
1725 public static function alterBadge($labelName, &$label, &$format, &$participant) {
1726 return self::singleton()
1727 ->invoke(4, $labelName, $label, $format, $participant, self::$_nullObject, self::$_nullObject, 'civicrm_alterBadge');
1728 }
1729
1730
1731 /**
1732 * This hook is called before encoding data in barcode
1733 *
1734 * @param array $data
1735 * Associated array of values available for encoding.
1736 * @param string $type
1737 * Type of barcode, classic barcode or QRcode.
1738 * @param string $context
1739 * Where this hooks is invoked.
1740 *
1741 * @return mixed
1742 */
1743 public static function alterBarcode(&$data, $type = 'barcode', $context = 'name_badge') {
1744 return self::singleton()->invoke(3, $data, $type, $context, self::$_nullObject,
1745 self::$_nullObject, self::$_nullObject, 'civicrm_alterBarcode');
1746 }
1747
1748 /**
1749 * Modify or replace the Mailer object used for outgoing mail.
1750 *
1751 * @param object $mailer
1752 * The default mailer produced by normal configuration; a PEAR "Mail" class (like those returned by Mail::factory)
1753 * @param string $driver
1754 * The type of the default mailer (eg "smtp", "sendmail", "mock", "CRM_Mailing_BAO_Spool")
1755 * @param array $params
1756 * The default mailer config options
1757 *
1758 * @return mixed
1759 * @see Mail::factory
1760 */
1761 public static function alterMail(&$mailer, $driver, $params) {
1762 return self::singleton()
1763 ->invoke(3, $mailer, $driver, $params, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_alterMailer');
1764 }
1765
1766 /**
1767 * This hook is called while building the core search query,
1768 * so hook implementers can provide their own query objects which alters/extends core search.
1769 *
1770 * @param array $queryObjects
1771 * @param string $type
1772 *
1773 * @return mixed
1774 */
1775 public static function queryObjects(&$queryObjects, $type = 'Contact') {
1776 return self::singleton()
1777 ->invoke(2, $queryObjects, $type, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_queryObjects');
1778 }
1779
1780 /**
1781 * This hook is called while viewing contact dashboard
1782 *
1783 * @param array $availableDashlets
1784 * List of dashlets; each is formatted per api/v3/Dashboard
1785 * @param array $defaultDashlets
1786 * List of dashlets; each is formatted per api/v3/DashboardContact
1787 *
1788 * @return mixed
1789 */
1790 public static function dashboard_defaults($availableDashlets, &$defaultDashlets) {
1791 return self::singleton()
1792 ->invoke(2, $availableDashlets, $defaultDashlets, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_dashboard_defaults');
1793 }
1794
1795 /**
1796 * This hook is called before a case merge (or a case reassign)
1797 *
1798 * @param int $mainContactId
1799 * @param int $mainCaseId
1800 * @param int $otherContactId
1801 * @param int $otherCaseId
1802 * @param bool $changeClient
1803 *
1804 * @return void
1805 */
1806 public static function pre_case_merge($mainContactId, $mainCaseId = NULL, $otherContactId = NULL, $otherCaseId = NULL, $changeClient = FALSE) {
1807 return self::singleton()
1808 ->invoke(5, $mainContactId, $mainCaseId, $otherContactId, $otherCaseId, $changeClient, self::$_nullObject, 'civicrm_pre_case_merge');
1809 }
1810
1811 /**
1812 * This hook is called after a case merge (or a case reassign)
1813 *
1814 * @param int $mainContactId
1815 * @param int $mainCaseId
1816 * @param int $otherContactId
1817 * @param int $otherCaseId
1818 * @param bool $changeClient
1819 *
1820 * @return void
1821 */
1822 public static function post_case_merge($mainContactId, $mainCaseId = NULL, $otherContactId = NULL, $otherCaseId = NULL, $changeClient = FALSE) {
1823 return self::singleton()
1824 ->invoke(5, $mainContactId, $mainCaseId, $otherContactId, $otherCaseId, $changeClient, self::$_nullObject, 'civicrm_post_case_merge');
1825 }
1826
1827 /**
1828 * Issue CRM-14276
1829 * Add a hook for altering the display name
1830 *
1831 * hook_civicrm_contact_get_displayname(&$display_name, $objContact)
1832 *
1833 * @param string $displayName
1834 * @param int $contactId
1835 * @param object $dao
1836 * The contact object.
1837 *
1838 * @return mixed
1839 */
1840 public static function alterDisplayName($displayName, $contactId, $dao) {
1841 return self::singleton()->invoke(3,
1842 $displayName, $contactId, $dao, self::$_nullObject, self::$_nullObject,
1843 self::$_nullObject, 'civicrm_contact_get_displayname'
1844 );
1845 }
1846
1847 /**
1848 * EXPERIMENTAL: This hook allows one to register additional Angular modules
1849 *
1850 * @param array $angularModules
1851 * List of modules.
1852 * @return null
1853 * the return value is ignored
1854 *
1855 * @code
1856 * function mymod_civicrm_angularModules(&$angularModules) {
1857 * $angularModules['myAngularModule'] = array('ext' => 'org.example.mymod', 'js' => array('js/myAngularModule.js'));
1858 * $angularModules['myBigAngularModule'] = array('ext' => 'org.example.mymod', 'js' => array('js/part1.js', 'js/part2.js'), 'css' => array('css/myAngularModule.css'));
1859 * }
1860 * @endcode
1861 */
1862 public static function angularModules(&$angularModules) {
1863 return self::singleton()->invoke(1, $angularModules,
1864 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
1865 'civicrm_angularModules'
1866 );
1867 }
1868
1869 /**
1870 * This hook fires whenever a record in a case changes.
1871 *
1872 * @param \Civi\CCase\Analyzer $analyzer
1873 */
1874 public static function caseChange(\Civi\CCase\Analyzer $analyzer) {
1875 $event = new \Civi\CCase\Event\CaseChangeEvent($analyzer);
1876 \Civi\Core\Container::singleton()->get('dispatcher')->dispatch("hook_civicrm_caseChange", $event);
1877
1878 return self::singleton()->invoke(1, $angularModules,
1879 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
1880 'civicrm_caseChange'
1881 );
1882 }
1883
1884 /**
1885 * Generate a default CRUD URL for an entity
1886 *
1887 * @param array $spec
1888 * With keys:.
1889 * - action: int, eg CRM_Core_Action::VIEW or CRM_Core_Action::UPDATE
1890 * - entity_table: string
1891 * - entity_id: int
1892 * @param CRM_Core_DAO $bao
1893 * @param array $link
1894 * To define the link, add these keys to $link:.
1895 * - title: string
1896 * - path: string
1897 * - query: array
1898 * - url: string (used in lieu of "path"/"query")
1899 * Note: if making "url" CRM_Utils_System::url(), set $htmlize=false
1900 * @return mixed
1901 */
1902 public static function crudLink($spec, $bao, &$link) {
1903 return self::singleton()->invoke(3, $spec, $bao, $link,
1904 self::$_nullObject, self::$_nullObject, self::$_nullObject,
1905 'civicrm_crudLink'
1906 );
1907 }
1908
1909 /**
1910 * @param array <CRM_Core_FileSearchInterface> $fileSearches
1911 * @return mixed
1912 */
1913 public static function fileSearches(&$fileSearches) {
1914 return self::singleton()->invoke(1, $fileSearches,
1915 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
1916 'civicrm_fileSearches'
1917 );
1918 }
1919 }