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