Import from SVN (r45945, r596)
[civicrm-core.git] / CRM / Utils / Hook.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
32 * $Id: $
33 *
34 */
35
36abstract class CRM_Utils_Hook {
37
38 // Allowed values for dashboard hook content placement
39 // Default - place content below activity list
40 CONST DASHBOARD_BELOW = 1;
41 // Place content above activity list
42 CONST DASHBOARD_ABOVE = 2;
43 // Don't display activity list at all
44 CONST DASHBOARD_REPLACE = 3;
45
46 // by default - place content below existing content
47 CONST SUMMARY_BELOW = 1;
48 // pace hook content above
49 CONST SUMMARY_ABOVE = 2;
50 // create your own summarys
51 CONST SUMMARY_REPLACE = 3;
52
53 static $_nullObject = NULL;
54
55 /**
56 * We only need one instance of this object. So we use the singleton
57 * pattern and cache the instance in this variable
58 *
59 * @var object
60 * @static
61 */
62 static private $_singleton = NULL;
63
64 /**
65 * @var bool
66 */
67 private $commonIncluded = FALSE;
68
69 /**
70 * @var array(string)
71 */
72 private $commonCiviModules = array();
73
74 /**
75 * Constructor and getter for the singleton instance
76 *
77 * @return instance of $config->userHookClass
78 */
79 static function singleton($fresh = FALSE) {
80 if (self::$_singleton == NULL || $fresh) {
81 $config = CRM_Core_Config::singleton();
82 $class = $config->userHookClass;
83 require_once (str_replace('_', DIRECTORY_SEPARATOR, $config->userHookClass) . '.php');
84 self::$_singleton = new $class();
85 }
86 return self::$_singleton;
87 }
88
89 abstract function invoke($numParams,
90 &$arg1, &$arg2, &$arg3, &$arg4, &$arg5,
91 $fnSuffix
92 );
93
94 /**
95 * Get a list of modules implementing the given hook.
96 * @return Array of module names.
97 */
98 abstract function moduleImplements($hookName);
99
100 function commonInvoke($numParams,
101 &$arg1, &$arg2, &$arg3, &$arg4, &$arg5,
102 $fnSuffix, $fnPrefix
103 ) {
104
105 $this->commonBuildModuleList($fnPrefix);
106
107 return $this->runHooks($this->commonCiviModules, $fnSuffix,
108 $numParams, $arg1, $arg2, $arg3, $arg4, $arg5
109 );
110 }
111
112 /**
113 * Build the list of modules to be processed for hooks.
114 */
115 function commonBuildModuleList($fnPrefix) {
116 if (!$this->commonIncluded) {
117 // include external file
118 $this->commonIncluded = TRUE;
119
120 $config = CRM_Core_Config::singleton();
121 if (!empty($config->customPHPPathDir) &&
122 file_exists("{$config->customPHPPathDir}/civicrmHooks.php")
123 ) {
124 @include_once ("civicrmHooks.php");
125 }
126
127 if (!empty($fnPrefix)) {
128 $this->commonCiviModules[$fnPrefix] = $fnPrefix;
129 }
130
131 $this->requireCiviModules($this->commonCiviModules);
132 }
133 }
134
135 /**
136 * Get a list of modules implementing the given hook.
137 * @return Array of module names.
138 */
139 function commonModuleImplements($fnSuffix, $fnPrefix) {
140 $return = array();
141
142 $this->commonBuildModuleList($fnPrefix);
143
144 foreach ($this->commonCiviModules as $module) {
145 $fnName = "{$module}_{$fnSuffix}";
146 if (function_exists($fnName)) {
147 $return[] = $module;
148 }
149 }
150 return $return;
151 }
152
153 function runHooks(&$civiModules, $fnSuffix, $numParams,
154 &$arg1, &$arg2, &$arg3, &$arg4, &$arg5
155 ) {
156 $result = $fResult = array();
157
158 foreach ($civiModules as $module) {
159 $fnName = "{$module}_{$fnSuffix}";
160 if (function_exists($fnName)) {
161 switch ($numParams) {
162 case 0:
163 $fResult = $fnName();
164 break;
165
166 case 1:
167 $fResult = $fnName($arg1);
168 break;
169
170 case 2:
171 $fResult = $fnName($arg1, $arg2);
172 break;
173
174 case 3:
175 $fResult = $fnName($arg1, $arg2, $arg3);
176 break;
177
178 case 4:
179 $fResult = $fnName($arg1, $arg2, $arg3, $arg4);
180 break;
181
182 case 5:
183 $fResult = $fnName($arg1, $arg2, $arg3, $arg4, $arg5);
184 break;
185
186 default:
187 CRM_Core_Error::fatal(ts('Invalid hook invocation'));
188 break;
189 }
190 }
191
192 if (!empty($fResult) &&
193 is_array($fResult)) {
194 $result = array_merge($result, $fResult);
195 }
196 }
197
198 return empty($result) ? TRUE : $result;
199 }
200
201 function requireCiviModules(&$moduleList) {
202 $civiModules = CRM_Core_PseudoConstant::getModuleExtensions();
203 foreach ($civiModules as $civiModule) {
204 if (!file_exists($civiModule['filePath'])) {
205 CRM_Core_Session::setStatus(
206 ts( 'Error loading module file (%1). Please restore the file or disable the module.', array(1 => $civiModule['filePath']) ),
207 ts( 'Warning'), 'error');
208 continue;
209 }
210 include_once $civiModule['filePath'];
211 $moduleList[$civiModule['prefix']] = $civiModule['prefix'];
212 }
213 }
214
215 /**
216 * This hook is called before a db write on some core objects.
217 * This hook does not allow the abort of the operation
218 *
219 * @param string $op the type of operation being performed
220 * @param string $objectName the name of the object
221 * @param object $id the object id if available
222 * @param array $params the parameters used for object creation / editing
223 *
224 * @return null the return value is ignored
225 * @access public
226 */
227 static function pre($op, $objectName, $id, &$params) {
228 return self::singleton()->invoke(4, $op, $objectName, $id, $params, $op, 'civicrm_pre');
229 }
230
231 /**
232 * This hook is called after a db write on some core objects.
233 *
234 * @param string $op the type of operation being performed
235 * @param string $objectName the name of the object
236 * @param int $objectId the unique identifier for the object
237 * @param object $objectRef the reference to the object if available
238 *
239 * @return mixed based on op. pre-hooks return a boolean or
240 * an error message which aborts the operation
241 * @access public
242 */
243 static function post($op, $objectName, $objectId, &$objectRef) {
244 return self::singleton()->invoke(4, $op, $objectName, $objectId, $objectRef, $op, 'civicrm_post');
245 }
246
247 /**
248 * This hook to assessment grant
249 *
250 * @param string $param the params
251 *
252 * @access public
253 */
254 static function grantAssessment( &$params ) {
255 return self::singleton( )->invoke( 1, $params, self::$_nullObject , self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_grantAssessment' );
256 }
257
258 /**
259 * This hook retrieves links from other modules and injects it into
260 * the view contact tabs
261 *
262 * @param string $op the type of operation being performed
263 * @param string $objectName the name of the object
264 * @param int $objectId the unique identifier for the object
265 * @params array $links (optional ) the links array (introduced in v3.2)
266 *
267 * @return array|null an array of arrays, each element is a tuple consisting of id, url, img, title, weight
268 *
269 * @access public
270 */
271 static function links($op, $objectName, &$objectId, &$links, &$mask = NULL) {
272 return self::singleton()->invoke(5, $op, $objectName, $objectId, $links, $mask, 'civicrm_links');
273 }
274
275 /**
276 * This hook is invoked when building a CiviCRM form. This hook should also
277 * be used to set the default values of a form element
278 *
279 * @param string $formName the name of the form
280 * @param object $form reference to the form object
281 *
282 * @return null the return value is ignored
283 */
284 static function buildForm($formName, &$form) {
285 return self::singleton()->invoke(2, $formName, $form, $formName, $formName, $formName, 'civicrm_buildForm');
286 }
287
288 /**
289 * This hook is invoked when a CiviCRM form is submitted. If the module has injected
290 * any form elements, this hook should save the values in the database
291 *
292 * @param string $formName the name of the form
293 * @param object $form reference to the form object
294 *
295 * @return null the return value is ignored
296 */
297 static function postProcess($formName, &$form) {
298 return self::singleton()->invoke(2, $formName, $form, $formName, $formName, $formName, 'civicrm_postProcess');
299 }
300
301 /**
302 * This hook is invoked during all CiviCRM form validation. An array of errors
303 * detected is returned. Else we assume validation succeeded.
304 *
305 * @param string $formName the name of the form
306 * @param array &$fields the POST parameters as filtered by QF
307 * @param array &$files the FILES parameters as sent in by POST
308 * @param array &$form the form object
309 *
310 * @return mixed formRule hooks return a boolean or
311 * an array of error messages which display a QF Error
312 * @access public
313 */
314 static function validate($formName, &$fields, &$files, &$form) {
315 return self::singleton()->invoke(4, $formName, $fields, $files, $form, $formName, 'civicrm_validate');
316 }
317
318 /**
319 * This hook is invoked during all CiviCRM form validation. An array of errors
320 * detected is returned. Else we assume validation succeeded.
321 *
322 * @param string $formName the name of the form
323 * @param array &$fields the POST parameters as filtered by QF
324 * @param array &$files the FILES parameters as sent in by POST
325 * @param array &$form the form object
326 * @param array &$errors the array of errors.
327 *
328 * @return mixed formRule hooks return a boolean or
329 * an array of error messages which display a QF Error
330 * @access public
331 */
332 static function validateForm($formName, &$fields, &$files, &$form, &$errors) {
333 return self::singleton()->invoke(5, $formName, $fields, $files, $form, $errors, 'civicrm_validateForm');
334 }
335
336 /**
337 * This hook is called before a db write on a custom table
338 *
339 * @param string $op the type of operation being performed
340 * @param string $groupID the custom group ID
341 * @param object $entityID the entityID of the row in the custom table
342 * @param array $params the parameters that were sent into the calling function
343 *
344 * @return null the return value is ignored
345 * @access public
346 */
347 static function custom($op, $groupID, $entityID, &$params) {
348 return self::singleton()->invoke(4, $op, $groupID, $entityID, $params, $op, 'civicrm_custom');
349 }
350
351 /**
352 * This hook is called when composing the ACL where clause to restrict
353 * visibility of contacts to the logged in user
354 *
355 * @param int $type the type of permission needed
356 * @param array $tables (reference ) add the tables that are needed for the select clause
357 * @param array $whereTables (reference ) add the tables that are needed for the where clause
358 * @param int $contactID the contactID for whom the check is made
359 * @param string $where the currrent where clause
360 *
361 * @return null the return value is ignored
362 * @access public
363 */
364 static function aclWhereClause($type, &$tables, &$whereTables, &$contactID, &$where) {
365 return self::singleton()->invoke(5, $type, $tables, $whereTables, $contactID, $where, 'civicrm_aclWhereClause');
366 }
367
368 /**
369 * This hook is called when composing the ACL where clause to restrict
370 * visibility of contacts to the logged in user
371 *
372 * @param int $type the type of permission needed
373 * @param int $contactID the contactID for whom the check is made
374 * @param string $tableName the tableName which is being permissioned
375 * @param array $allGroups the set of all the objects for the above table
376 * @param array $currentGroups the set of objects that are currently permissioned for this contact
377 *
378 * @return null the return value is ignored
379 * @access public
380 */
381 static function aclGroup($type, $contactID, $tableName, &$allGroups, &$currentGroups) {
382 return self::singleton()->invoke(5, $type, $contactID, $tableName, $allGroups, $currentGroups, 'civicrm_aclGroup');
383 }
384
385 /**
386 * This hook is called when building the menu table
387 *
388 * @param array $files The current set of files to process
389 *
390 * @return null the return value is ignored
391 * @access public
392 */
393 static function xmlMenu(&$files) {
394 return self::singleton()->invoke(1, $files,
395 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
396 'civicrm_xmlMenu'
397 );
398 }
399
400 /**
401 * This hook is called for declaring managed entities via API
402 *
403 * @param array $entities List of pending entities
404 *
405 * @return null the return value is ignored
406 * @access public
407 */
408 static function managed(&$entities) {
409 return self::singleton()->invoke(1, $entities,
410 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
411 'civicrm_managed'
412 );
413 }
414
415 /**
416 * This hook is called when rendering the dashboard (q=civicrm/dashboard)
417 *
418 * @param int $contactID - the contactID for whom the dashboard is being rendered
419 * @param int $contentPlacement - (output parameter) where should the hook content be displayed relative to the activity list
420 *
421 * @return string the html snippet to include in the dashboard
422 * @access public
423 */
424 static function dashboard($contactID, &$contentPlacement = self::DASHBOARD_BELOW) {
425 $retval = self::singleton()->invoke(2, $contactID, $contentPlacement,
426 self::$_nullObject, self::$_nullObject, self::$_nullObject,
427 'civicrm_dashboard'
428 );
429
430 /*
431 * Note we need this seemingly unnecessary code because in the event that the implementation
432 * of the hook declares the second parameter but doesn't set it, then it comes back unset even
433 * though we have a default value in this function's declaration above.
434 */
435 if (!isset($contentPlacement)) {
436 $contentPlacement = self::DASHBOARD_BELOW;
437 }
438
439 return $retval;
440 }
441
442 /**
443 * This hook is called before storing recently viewed items.
444 *
445 * @param array $recentArray - an array of recently viewed or processed items, for in place modification
446 *
447 * @return array
448 * @access public
449 */
450 static function recent(&$recentArray) {
451 return self::singleton()->invoke(1, $recentArray,
452 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
453 'civicrm_recent'
454 );
455 }
456
457 /**
458 * This hook is called when building the amount structure for a Contribution or Event Page
459 *
460 * @param int $pageType - is this a contribution or event page
461 * @param object $form - reference to the form object
462 * @param array $amount - the amount structure to be displayed
463 *
464 * @return null
465 * @access public
466 */
467 static function buildAmount($pageType, &$form, &$amount) {
468 return self::singleton()->invoke(3, $pageType, $form, $amount, self::$_nullObject, self::$_nullObject, 'civicrm_buildAmount');
469 }
470
471 /**
472 * This hook is called when building the state list for a particular country.
473 *
474 * @param array $countryID - the country id whose states are being selected.
475 *
476 * @return null
477 * @access public
478 */
479 static function buildStateProvinceForCountry($countryID, &$states) {
480 return self::singleton()->invoke(2, $countryID, $states,
481 self::$_nullObject, self::$_nullObject, self::$_nullObject,
482 'civicrm_buildStateProvinceForCountry'
483 );
484 }
485
486 /**
487 * This hook is called when rendering the tabs for a contact (q=civicrm/contact/view)c
488 *
489 * @param array $tabs - the array of tabs that will be displayed
490 * @param int $contactID - the contactID for whom the dashboard is being rendered
491 *
492 * @return null
493 * @access public
494 */
495 static function tabs(&$tabs, $contactID) {
496 return self::singleton()->invoke(2, $tabs, $contactID,
497 self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_tabs'
498 );
499 }
500
501 /**
502 * This hook is called when sending an email / printing labels
503 *
504 * @param array $tokens - the list of tokens that can be used for the contact
505 *
506 * @return null
507 * @access public
508 */
509 static function tokens(&$tokens) {
510 return self::singleton()->invoke(1, $tokens,
511 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_tokens'
512 );
513 }
514
515 /**
516 * This hook is called when sending an email / printing labels to get the values for all the
517 * tokens returned by the 'tokens' hook
518 *
519 * @param array $details - the array to store the token values indexed by contactIDs (unless it a single)
520 * @param array $contactIDs - an array of contactIDs
521 * @param int $jobID - the jobID if this is associated with a CiviMail mailing
522 * @param array $tokens - the list of tokens associated with the content
523 * @param string $className - the top level className from where the hook is invoked
524 *
525 * @return null
526 * @access public
527 */
528 static function tokenValues(&$details,
529 $contactIDs,
530 $jobID = NULL,
531 $tokens = array(),
532 $className = NULL
533 ) {
534 return self::singleton()->invoke(5, $details, $contactIDs, $jobID, $tokens, $className, 'civicrm_tokenValues');
535 }
536
537 /**
538 * This hook is called before a CiviCRM Page is rendered. You can use this hook to insert smarty variables
539 * in a template
540 *
541 * @param object $page - the page that will be rendered
542 *
543 * @return null
544 * @access public
545 */
546 static function pageRun(&$page) {
547 return self::singleton()->invoke(1, $page,
548 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
549 'civicrm_pageRun'
550 );
551 }
552
553 /**
554 * This hook is called after a copy of an object has been made. The current objects are
555 * Event, Contribution Page and UFGroup
556 *
557 * @param string $objectName - name of the object
558 * @param object $object - reference to the copy
559 *
560 * @return null
561 * @access public
562 */
563 static function copy($objectName, &$object) {
564 return self::singleton()->invoke(2, $objectName, $object,
565 self::$_nullObject, self::$_nullObject, self::$_nullObject,
566 'civicrm_copy'
567 );
568 }
569
570 /**
571 * This hook is called when a contact unsubscribes from a mailing. It allows modules
572 * to override what the contacts are removed from.
573 *
574 * @param int $mailing_id - the id of the mailing to unsub from
575 * @param int $contact_id - the id of the contact who is unsubscribing
576 * @param array / int $groups - array of groups the contact will be removed from
577 **/
578 static function unsubscribeGroups($op, $mailingId, $contactId, &$groups, &$baseGroups) {
579 return self::singleton()->invoke(5, $op, $mailingId, $contactId, $groups, $baseGroups, 'civicrm_unsubscribeGroups');
580 }
581
582 /**
583 * This hook is called when CiviCRM needs to edit/display a custom field with options (select, radio, checkbox, adv multiselect)
584 *
585 * @param int $customFieldID - the custom field ID
586 * @param array $options - the current set of options for that custom field.
587 * You can add/remove existing options.
588 * Important: This array may contain meta-data about the field that is needed elsewhere, so it is important to be careful to not overwrite the array.
589 * Only add/edit/remove the specific field options you intend to affect.
590 * @param boolean $detailedFormat - if true, the options are in an ID => array ( 'id' => ID, 'label' => label, 'value' => value ) format
591 */
592 static function customFieldOptions($customFieldID, &$options, $detailedFormat = FALSE) {
593 return self::singleton()->invoke(3, $customFieldID, $options, $detailedFormat,
594 self::$_nullObject, self::$_nullObject,
595 'civicrm_customFieldOptions'
596 );
597 }
598
599 /**
600 *
601 * This hook is called to display the list of actions allowed after doing a search.
602 * This allows the module developer to inject additional actions or to remove existing actions.
603 *
604 * @param string $objectType - the object type for this search
605 * - activity, campaign, case, contact, contribution, event, grant, membership, and pledge are supported.
606 * @param array $tasks - the current set of tasks for that custom field.
607 * You can add/remove existing tasks.
608 * Each task needs to have a title (eg 'title' => ts( 'Add Contacts to Group')) and a class (eg 'class' => 'CRM_Contact_Form_Task_AddToGroup').
609 * Optional result (boolean) may also be provided. Class can be an array of classes (not sure what that does :( ).
610 * The key for new Task(s) should not conflict with the keys for core tasks of that $objectType, which can be found in CRM/$objectType/Task.php.
611 */
612 static function searchTasks($objectType, &$tasks) {
613 return self::singleton()->invoke(2, $objectType, $tasks,
614 self::$_nullObject, self::$_nullObject, self::$_nullObject,
615 'civicrm_searchTasks'
616 );
617 }
618
619 static function eventDiscount(&$form, &$params) {
620 return self::singleton()->invoke(2, $form, $params,
621 self::$_nullObject, self::$_nullObject, self::$_nullObject,
622 'civicrm_eventDiscount'
623 );
624 }
625
626 /**
627 * This hook is called when composing a mailing. You can include / exclude other groups as needed.
628 *
629 * @param unknown_type $form - the form object for which groups / mailings being displayed
630 * @param array $groups - the list of groups being included / excluded
631 * @param array $mailings - the list of mailings being included / excluded
632 */
633 static function mailingGroups(&$form, &$groups, &$mailings) {
634 return self::singleton()->invoke(3, $form, $groups, $mailings,
635 self::$_nullObject, self::$_nullObject,
636 'civicrm_mailingGroups'
637 );
638 }
639
640 /**
641 * This hook is called when composing the array of membershipTypes and their cost during a membership registration (new or renewal).
642 * Note the hook is called on initial page load and also reloaded after submit (PRG pattern).
643 * You can use it to alter the membership types when first loaded, or after submission
644 * (for example if you want to gather data in the form and use it to alter the fees).
645 *
646 * @param unknown_type $form - the form object that is presenting the page
647 * @param array $membershipTypes - the array of membership types and their amount
648 */
649 static function membershipTypeValues(&$form, &$membershipTypes) {
650 return self::singleton()->invoke(2, $form, $membershipTypes,
651 self::$_nullObject, self::$_nullObject, self::$_nullObject,
652 'civicrm_membershipTypeValues'
653 );
654 }
655
656 /**
657 * This hook is called when rendering the contact summary
658 *
659 * @param int $contactID - the contactID for whom the summary is being rendered
660 * @param int $contentPlacement - (output parameter) where should the hook content be displayed relative to the existing content
661 *
662 * @return string the html snippet to include in the contact summary
663 * @access public
664 */
665 static function summary($contactID, &$content, &$contentPlacement = self::SUMMARY_BELOW) {
666 return self::singleton()->invoke(3, $contactID, $content, $contentPlacement,
667 self::$_nullObject, self::$_nullObject,
668 'civicrm_summary'
669 );
670 }
671
672 /**
673 * Use this hook to populate the list of contacts returned by Contact Reference custom fields.
674 * By default, Contact Reference fields will search on and return all CiviCRM contacts.
675 * If you want to limit the contacts returned to a specific group, or some other criteria
676 * - you can override that behavior by providing a SQL query that returns some subset of your contacts.
677 * The hook is called when the query is executed to get the list of contacts to display.
678 *
679 * @param unknown_type $query - - the query that will be executed (input and output parameter);
680 * It's important to realize that the ACL clause is built prior to this hook being fired,
681 * so your query will ignore any ACL rules that may be defined.
682 * Your query must return two columns:
683 * the contact 'data' to display in the autocomplete dropdown (usually contact.sort_name - aliased as 'data')
684 * the contact IDs
685 * @param string $name - the name string to execute the query against (this is the value being typed in by the user)
686 * @param string $context - the context in which this ajax call is being made (for example: 'customfield', 'caseview')
687 * @param int $id - the id of the object for which the call is being made.
688 * For custom fields, it will be the custom field id
689 */
690 static function contactListQuery(&$query, $name, $context, $id) {
691 return self::singleton()->invoke(4, $query, $name, $context, $id,
692 self::$_nullObject,
693 'civicrm_contactListQuery'
694 );
695 }
696
697 /**
698 * Hook definition for altering payment parameters before talking to a payment processor back end.
699 *
700 * Definition will look like this:
701 *
702 * function hook_civicrm_alterPaymentProcessorParams($paymentObj,
703 * &$rawParams, &$cookedParams);
704 *
705 * @param string $paymentObj
706 * instance of payment class of the payment processor invoked (e.g., 'CRM_Core_Payment_Dummy')
707 * @param array &$rawParams
708 * array of params as passed to to the processor
709 * @params array &$cookedParams
710 * params after the processor code has translated them into its own key/value pairs
711 *
712 * @return void
713 */
714 static function alterPaymentProcessorParams($paymentObj,
715 &$rawParams,
716 &$cookedParams
717 ) {
718 return self::singleton()->invoke(3, $paymentObj, $rawParams, $cookedParams,
719 self::$_nullObject, self::$_nullObject,
720 'civicrm_alterPaymentProcessorParams'
721 );
722 }
723
724 /**
725 * This hook is called when an email is about to be sent by CiviCRM.
726 *
727 * @param array $params - array fields include: groupName, from, toName, toEmail, subject, cc, bcc, text, html, returnPath, replyTo, headers, attachments (array)
728 * @param string $context - the context in which the hook is being invoked, eg 'civimail'
729 */
730 static function alterMailParams(&$params, $context = NULL) {
731 return self::singleton()->invoke(2, $params, $context,
732 self::$_nullObject, self::$_nullObject, self::$_nullObject,
733 'civicrm_alterMailParams'
734 );
735 }
736
737 /**
738 * This hook is called when rendering the Manage Case screen
739 *
740 * @param int $caseID - the case ID
741 *
742 * @return array of data to be displayed, where the key is a unique id to be used for styling (div id's) and the value is an array with keys 'label' and 'value' specifying label/value pairs
743 * @access public
744 */
745 static function caseSummary($caseID) {
746 return self::singleton()->invoke(1, $caseID,
747 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
748 'civicrm_caseSummary'
749 );
750 }
751
752 /**
753 * This hook is called soon after the CRM_Core_Config object has ben initialized.
754 * You can use this hook to modify the config object and hence behavior of CiviCRM dynamically.
755
756 * @param array $config - the config object
757 */
758 static function config(&$config) {
759 return self::singleton()->invoke(1, $config,
760 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
761 'civicrm_config'
762 );
763 }
764
765 static function enableDisable($recordBAO, $recordID, $isActive) {
766 return self::singleton()->invoke(3, $recordBAO, $recordID, $isActive,
767 self::$_nullObject, self::$_nullObject,
768 'civicrm_enableDisable'
769 );
770 }
771
772 /**
773 * This hooks allows to change option values
774 *
775 * @param $options associated array of option values / id
776 * @param $name option group name
777 *
778 * @access public
779 */
780 static function optionValues(&$options, $name) {
781 return self::singleton()->invoke(2, $options, $name,
782 self::$_nullObject, self::$_nullObject, self::$_nullObject,
783 'civicrm_optionValues'
784 );
785 }
786
787 /**
788 * This hook allows modification of the navigation menu.
789 *
790 * @param $params associated array of navigation menu entry to Modify/Add
791 * @access public
792 */
793 static function navigationMenu(&$params) {
794 return self::singleton()->invoke(1, $params,
795 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
796 'civicrm_navigationMenu'
797 );
798 }
799
800 /**
801 * This hook allows modification of the data used to perform merging of duplicates.
802 *
803 * @param string $type the type of data being passed (cidRefs|eidRefs|relTables|sqls)
804 * @param array $data the data, as described in $type
805 * @param int $mainId contact_id of the contact that survives the merge
806 * @param int $otherId contact_id of the contact that will be absorbed and deleted
807 * @param array $tables when $type is "sqls", an array of tables as it may have been handed to the calling function
808 *
809 * @access public
810 */
811 static function merge($type, &$data, $mainId = NULL, $otherId = NULL, $tables = NULL) {
812 return self::singleton()->invoke(5, $type, $data, $mainId, $otherId, $tables, 'civicrm_merge');
813 }
814
815 /**
816 * This hook provides a way to override the default privacy behavior for notes.
817 *
818 * @param array $note (reference) Associative array of values for this note
819 *
820 * @access public
821 */
822 static function notePrivacy(&$noteValues) {
823 return self::singleton()->invoke(1, $noteValues,
824 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
825 'civicrm_notePrivacy'
826 );
827 }
828
829 /**
830 * This hook is called before record is exported as CSV
831 *
832 * @param string $exportTempTable - name of the temporary export table used during export
833 * @param array $headerRows - header rows for output
834 * @param array $sqlColumns - SQL columns
835 * @param int $exportMode - export mode ( contact, contribution, etc...)
836 *
837 * @return void
838 * @access public
839 */
840 static function export(&$exportTempTable, &$headerRows, &$sqlColumns, &$exportMode) {
841 return self::singleton()->invoke(4, $exportTempTable, $headerRows, $sqlColumns, $exportMode,
842 self::$_nullObject,
843 'civicrm_export'
844 );
845 }
846
847 /**
848 * This hook allows modification of the queries constructed from dupe rules.
849 *
850 * @param string $obj object of rulegroup class
851 * @param string $type type of queries e.g table / threshold
852 * @param array $query set of queries
853 *
854 * @access public
855 */
856 static function dupeQuery($obj, $type, &$query) {
857 return self::singleton()->invoke(3, $obj, $type, $query,
858 self::$_nullObject, self::$_nullObject,
859 'civicrm_dupeQuery'
860 );
861 }
862
863 /**
864 * This hook is called AFTER EACH email has been processed by the script bin/EmailProcessor.php
865 *
866 * @param string $type type of mail processed: 'activity' OR 'mailing'
867 * @param array &$params the params that were sent to the CiviCRM API function
868 * @param object $mail the mail object which is an ezcMail class
869 * @param array &$result the result returned by the api call
870 * @param string $action (optional ) the requested action to be performed if the types was 'mailing'
871 *
872 * @access public
873 */
874 static function emailProcessor($type, &$params, $mail, &$result, $action = NULL) {
875 return self::singleton()->invoke(5, $type, $params, $mail, $result, $action, 'civicrm_emailProcessor');
876 }
877
878 /**
879 * This hook is called after a row has been processed and the
880 * record (and associated records imported
881 *
882 * @param string $object - object being imported (for now Contact only, later Contribution, Activity, Participant and Member)
883 * @param string $usage - hook usage/location (for now process only, later mapping and others)
884 * @param string $objectRef - import record object
885 * @param array $params - array with various key values: currently
886 * contactID - contact id
887 * importID - row id in temp table
888 * importTempTable - name of tempTable
889 * fieldHeaders - field headers
890 * fields - import fields
891 *
892 * @return void
893 * @access public
894 */
895 static function import($object, $usage, &$objectRef, &$params) {
896 return self::singleton()->invoke(4, $object, $usage, $objectRef, $params,
897 self::$_nullObject,
898 'civicrm_import'
899 );
900 }
901
902 /**
903 * This hook is called when API permissions are checked (cf. civicrm_api3_api_check_permission()
904 * in api/v3/utils.php and _civicrm_api3_permissions() in CRM/Core/DAO/.permissions.php).
905 *
906 * @param string $entity the API entity (like contact)
907 * @param string $action the API action (like get)
908 * @param array &$params the API parameters
909 * @param array &$permisisons the associative permissions array (probably to be altered by this hook)
910 */
911 static function alterAPIPermissions($entity, $action, &$params, &$permissions) {
912 return self::singleton()->invoke(4, $entity, $action, $params, $permissions,
913 self::$_nullObject,
914 'civicrm_alterAPIPermissions'
915 );
916 }
917
918 static function postSave(&$dao) {
919 $hookName = 'civicrm_postSave_' . $dao->getTableName();
920 return self::singleton()->invoke(1, $dao,
921 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
922 $hookName
923 );
924 }
925
926 /**
927 * This hook allows user to customize context menu Actions on contact summary page.
928 *
929 * @param array $actions Array of all Actions in contextmenu.
930 * @param int $contactID ContactID for the summary page
931 */
932 static function summaryActions(&$actions, $contactID = NULL) {
933 return self::singleton()->invoke(2, $actions, $contactID,
934 self::$_nullObject, self::$_nullObject, self::$_nullObject,
935 'civicrm_summaryActions'
936 );
937 }
938
939 /**
940 * This hook is called from CRM_Core_Selector_Controller through which all searches in civicrm go.
941 * This enables us hook implementors to modify both the headers and the rows
942 *
943 * The BIGGEST drawback with this hook is that you may need to modify the result template to include your
944 * fields. The result files are CRM/{Contact,Contribute,Member,Event...}/Form/Selector.tpl
945 *
946 * However, if you use the same number of columns, you can overwrite the existing columns with the values that
947 * you want displayed. This is a hackish, but avoids template modification.
948 *
949 * @param string $objectName the component name that we are doing the search
950 * activity, campaign, case, contact, contribution, event, grant, membership, and pledge
951 * @param array &$headers the list of column headers, an associative array with keys: ( name, sort, order )
952 * @param array &$rows the list of values, an associate array with fields that are displayed for that component
953 * @param array &$seletor the selector object. Allows you access to the context of the search
954 *
955 * @return void modify the header and values object to pass the data u need
956 */
957 static function searchColumns($objectName, &$headers, &$rows, &$selector) {
958 return self::singleton()->invoke(4, $objectName, $headers, $rows, $selector,
959 self::$_nullObject,
960 'civicrm_searchColumns'
961 );
962 }
963
964 /**
965 * This hook is called when uf groups are being built for a module.
966 *
967 * @param string $moduleName module name.
968 * @param array $ufGroups array of ufgroups for a module.
969 *
970 * @return null
971 * @access public
972 */
973 static function buildUFGroupsForModule($moduleName, &$ufGroups) {
974 return self::singleton()->invoke(2, $moduleName, $ufGroups,
975 self::$_nullObject, self::$_nullObject, self::$_nullObject,
976 'civicrm_buildUFGroupsForModule'
977 );
978 }
979
980 /**
981 * This hook is called when we are determining the contactID for a specific
982 * email address
983 *
984 * @param string $email the email address
985 * @param int $contactID the contactID that matches this email address, IF it exists
986 * @param array $result (reference) has two fields
987 * contactID - the new (or same) contactID
988 * action - 3 possible values:
989 * CRM_Utils_Mail_Incoming::EMAILPROCESSOR_CREATE_INDIVIDUAL - create a new contact record
990 * CRM_Utils_Mail_Incoming::EMAILPROCESSOR_OVERRIDE - use the new contactID
991 * CRM_Utils_Mail_Incoming::EMAILPROCESSOR_IGNORE - skip this email address
992 *
993 * @return null
994 * @access public
995 */
996 static function emailProcessorContact($email, $contactID, &$result) {
997 return self::singleton()->invoke(3, $email, $contactID, $result,
998 self::$_nullObject, self::$_nullObject,
999 'civicrm_emailProcessorContact'
1000 );
1001 }
1002
1003 /**
1004 * Hook definition for altering the generation of Mailing Labels
1005 *
1006 * @param array $args an array of the args in the order defined for the tcpdf multiCell api call
1007 * with the variable names below converted into string keys (ie $w become 'w'
1008 * as the first key for $args)
1009 * float $w Width of cells. If 0, they extend up to the right margin of the page.
1010 * float $h Cell minimum height. The cell extends automatically if needed.
1011 * string $txt String to print
1012 * mixed $border Indicates if borders must be drawn around the cell block. The value can
1013 * be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or
1014 * a string containing some or all of the following characters (in any order):
1015 * <ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul>
1016 * string $align Allows to center or align the text. Possible values are:<ul><li>L or empty string:
1017 * left align</li><li>C: center</li><li>R: right align</li><li>J: justification
1018 * (default value when $ishtml=false)</li></ul>
1019 * int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
1020 * int $ln Indicates where the current position should go after the call. Possible values are:<ul><li>0:
1021 * to the right</li><li>1: to the beginning of the next line [DEFAULT]</li><li>2: below</li></ul>
1022 * float $x x position in user units
1023 * float $y y position in user units
1024 * boolean $reseth if true reset the last cell height (default true).
1025 * int $stretch stretch carachter mode: <ul><li>0 = disabled</li><li>1 = horizontal scaling only if
1026 * necessary</li><li>2 = forced horizontal scaling</li><li>3 = character spacing only if
1027 * necessary</li><li>4 = forced character spacing</li></ul>
1028 * boolean $ishtml set to true if $txt is HTML content (default = false).
1029 * boolean $autopadding if true, uses internal padding and automatically adjust it to account for line width.
1030 * float $maxh maximum height. It should be >= $h and less then remaining space to the bottom of the page,
1031 * or 0 for disable this feature. This feature works only when $ishtml=false.
1032 *
1033 */
1034 static function alterMailingLabelParams(&$args) {
1035 return self::singleton()->invoke(1, $args,
1036 self::$_nullObject, self::$_nullObject,
1037 self::$_nullObject, self::$_nullObject,
1038 'civicrm_alterMailingLabelParams'
1039 );
1040 }
1041
1042 /**
1043 * This hooks allows alteration of generated page content
1044 *
1045 * @param $content previously generated content
1046 * @param $context context of content - page or form
1047 * @param $tplName the file name of the tpl
1048 * @param $object a reference to the page or form object
1049 *
1050 * @access public
1051 */
1052 static function alterContent(&$content, $context, $tplName, &$object) {
1053 return self::singleton()->invoke(4, $content, $context, $tplName, $object,
1054 self::$_nullObject,
1055 'civicrm_alterContent'
1056 );
1057 }
1058
1059 /**
1060 * This hook collects the trigger definition from all components
1061 *
1062 * @param $triggerInfo reference to an array of trigger information
1063 * each element has 4 fields:
1064 * table - array of tableName
1065 * when - BEFORE or AFTER
1066 * event - array of eventName - INSERT OR UPDATE OR DELETE
1067 * sql - array of statements optionally terminated with a ;
1068 * a statement can use the tokes {tableName} and {eventName}
1069 * to do token replacement with the table / event. This allows
1070 * templatizing logging and other hooks
1071 * @param string $tableName (optional) the name of the table that we are interested in only
1072 */
1073 static function triggerInfo(&$info, $tableName = NULL) {
1074 return self::singleton()->invoke(2, $info, $tableName,
1075 self::$_nullObject, self::$_nullObject,
1076 self::$_nullObject,
1077 'civicrm_triggerInfo'
1078 );
1079 }
1080
1081 /**
1082 * This hook is called when a module-extension is installed.
1083 * Each module will receive hook_civicrm_install during its own installation (but not during the installation of unrelated modules).
1084 */
1085 static function install() {
1086 return self::singleton()->invoke(0, self::$_nullObject,
1087 self::$_nullObject, self::$_nullObject,
1088 self::$_nullObject, self::$_nullObject,
1089 'civicrm_install'
1090 );
1091 }
1092
1093 /**
1094 * This hook is called when a module-extension is uninstalled.
1095 * Each module will receive hook_civicrm_uninstall during its own uninstallation (but not during the uninstallation of unrelated modules).
1096 */
1097 static function uninstall() {
1098 return self::singleton()->invoke(0, self::$_nullObject,
1099 self::$_nullObject, self::$_nullObject,
1100 self::$_nullObject, self::$_nullObject,
1101 'civicrm_uninstall'
1102 );
1103 }
1104
1105 /**
1106 * This hook is called when a module-extension is re-enabled.
1107 * Each module will receive hook_civicrm_enable during its own re-enablement (but not during the re-enablement of unrelated modules).
1108 */
1109 static function enable() {
1110 return self::singleton()->invoke(0, self::$_nullObject,
1111 self::$_nullObject, self::$_nullObject,
1112 self::$_nullObject, self::$_nullObject,
1113 'civicrm_enable'
1114 );
1115 }
1116
1117 /**
1118 * This hook is called when a module-extension is disabled.
1119 * Each module will receive hook_civicrm_disable during its own disablement (but not during the disablement of unrelated modules).
1120 */
1121 static function disable() {
1122 return self::singleton()->invoke(0, self::$_nullObject,
1123 self::$_nullObject, self::$_nullObject,
1124 self::$_nullObject, self::$_nullObject,
1125 'civicrm_disable'
1126 );
1127 }
1128
1129 static function alterReportVar($varType, &$var, &$object) {
1130 return self::singleton()->invoke(3, $varType, $var, $object,
1131 self::$_nullObject,
1132 self::$_nullObject,
1133 'civicrm_alterReportVar'
1134 );
1135 }
1136
1137 /**
1138 * This hook is called to drive database upgrades for extension-modules.
1139 *
1140 * @param string $op the type of operation being performed; 'check' or 'enqueue'
1141 * @param string $queue (for 'enqueue') the modifiable list of pending up upgrade tasks
1142 *
1143 * @return mixed based on op. 'check' returns a array(boolean) (TRUE if upgrades are pending)
1144 * 'enqueue' returns void
1145 * @access public
1146 */
1147 static function upgrade($op, CRM_Queue_Queue $queue = NULL) {
1148 return self::singleton()->invoke(2, $op, $queue,
1149 self::$_nullObject, self::$_nullObject,
1150 self::$_nullObject,
1151 'civicrm_upgrade'
1152 );
1153 }
1154
1155 /**
1156 * This hook is called when an email has been successfully sent by CiviCRM, but not on an error.
1157 *
1158 * @param array $params - the mailing parameters array fields include: groupName, from, toName, toEmail, subject, cc, bcc, text, html, returnPath, replyTo, headers, attachments (array)
1159 */
1160 static function postEmailSend(&$params) {
1161 return self::singleton()->invoke(1, $params,
1162 self::$_nullObject, self::$_nullObject,
1163 self::$_nullObject, self::$_nullObject,
1164 'civicrm_postEmailSend'
1165 );
1166 }
1167
1168 /**
1169 * This hook is called when Settings specifications are loaded
1170 *
1171 * @param array $settingsFolders - list of paths from which to derive metadata
1172 */
1173 static function alterSettingsFolders(&$settingsFolders) {
1174 return self::singleton()->invoke(1, $settingsFolders,
1175 self::$_nullObject, self::$_nullObject,
1176 self::$_nullObject, self::$_nullObject,
1177 'civicrm_alterSettingsFolders'
1178 );
1179 }
1180
1181 /**
1182 * This hook is called when Settings have been loaded from the xml
1183 * It is an opportunity for hooks to alter the data
1184 *
1185 * @param array $settingsMetaData - Settings Metadata
1186 * @domainID integer $domainID
1187 */
1188 static function alterSettingsMetaData(&$settingsMetaData, $domainID, $profile) {
1189 return self::singleton()->invoke(3, $settingsMetaData,
1190 $domainID, $profile,
1191 self::$_nullObject, self::$_nullObject,
1192 'civicrm_alterSettingsMetaData'
1193 );
1194 }
1195
1196 /**
1197 * This hook is called before running pending cron jobs.
1198 *
1199 * @param CRM_Core_JobManager $jobManager
1200 *
1201 * @return null the return value is ignored
1202 * @access public
1203 */
1204 static function cron($jobManager) {
1205 return self::singleton()->invoke(1,
1206 $jobManager, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
1207 'civicrm_cron'
1208 );
1209 }
1210
1211 /**
1212 * This hook is called when loading CMS permissions; use this hook to modify
1213 * the array of system permissions for CiviCRM.
1214 *
1215 * @param Array $permissions Array of permissions. See CRM_Core_Permission::getCorePermissions()
1216 * for the format of this array.
1217 *
1218 * @return null the return value is ignored
1219 * @access public
1220 */
1221 static function permission(&$permissions) {
1222 return self::singleton()->invoke(1, $permissions,
1223 self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
1224 'civicrm_permission'
1225 );
1226 }
1227}