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