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