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