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