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