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