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