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