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