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