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