-
Notifications
You must be signed in to change notification settings - Fork 0
/
mods.php
284 lines (256 loc) · 8.6 KB
/
mods.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<?php
/*-------------------------------------------------------+
| proVeg Germany Adjustments |
| Copyright (C) 2018 SYSTOPIA |
+--------------------------------------------------------+
| This program is released as free software under the |
| Affero GPL license. You can redistribute it and/or |
| modify it under the terms of this license which you |
| can read by viewing the included agpl.txt or online |
| at www.gnu.org/licenses/agpl.html. Removal of this |
| copyright header is strictly prohibited without |
| written permission from the original author(s). |
+--------------------------------------------------------*/
require_once 'mods.civix.php';
use CRM_Mods_ExtensionUtil as E;
/**
* Implements emailProcessor hook
*
* @see PV-8843
* @see https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_emailProcessorContact/
*/
function mods_civicrm_emailProcessorContact( $email, $contactID, &$result ) {
CRM_Mods_Emailprocessor::lookupContact($email, $contactID, $result);
}
/**
* Implements CiviSEPA hook
*/
function mods_civicrm_create_mandate(&$mandate_parameters) {
if (empty($mandate_parameters['reference'])) {
CRM_Mods_SepaMandate::createMandateReference($mandate_parameters);
}
}
/**
* Implements CiviSEPA hook to adjust collection date
*/
function mods_civicrm_defer_collection_date(&$collection_date, $creditor_id) {
while (!CRM_Mods_SepaMandate::is_collection_day($collection_date)) {
$collection_date = date('Y-m-d', strtotime("+1 day", strtotime($collection_date)));
}
}
/**
* Implements CiviSEPA hook to adjust transaction message ("Verwendungszweck")
*/
function mods_civicrm_modify_txmessage(&$txmessage, $info, $creditor) {
$txmessage = CRM_Mods_SepaMandate::generateTxMessage($info, $creditor);
}
function mods_civicrm_searchTasks($objectType, &$tasks) {
// add "Anonymise contributions" task to contact list:
if ($objectType == 'contact') {
$tasks[] = [
'title' => E::ts('Anonymise contributions'),
'class' => 'CRM_Mods_Form_Task_ContributionAnonymiser',
'result' => false
];
}
}
///**
// * Implements CiviSCRM hook to inject JS
// */
//function mods_civicrm_pageRun(&$page) {
// $pageName = $page->getVar('_name');
//}
/**
* Implements hook_civicrm_config().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_config
*/
function mods_civicrm_config(&$config) {
_mods_civix_civicrm_config($config);
require_once 'CRM/Xdedupe/ProVeg.php';
\Civi::dispatcher()->addSubscriber(new CRM_Xdedupe_ProVeg());
}
/**
* Implements hook_validateForm
*
* @see PV-11651
*/
function mods_civicrm_validateForm($formName, &$fields, &$files, &$form, &$errors) {
if (($formName == 'CRM_Contact_Form_Contact') || $formName == 'CRM_Contact_Form_Inline_CommunicationPreferences') {
if (($fields['preferred_language'] == NULL) || empty($fields['preferred_language'])) {
$errors['preferred_language'] = E::ts('%1 is a required field.', [1 => 'preferred_language']);
}
}
}
/**
* Implements hook_civicrm_install().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_install
*/
function mods_civicrm_install() {
_mods_civix_civicrm_install();
}
/**
* Implements hook_civicrm_enable().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_enable
*/
function mods_civicrm_enable() {
_mods_civix_civicrm_enable();
}
/**
* Add ME Menu (PV-7673)
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_navigationMenu
*/
function mods_civicrm_navigationMenu(&$menu) {
_mods_civix_insert_navigation_menu($menu, '', array(
'label' => E::ts('Me'),
'name' => 'my_contact',
'url' => '',
'icon' => 'fa fa-user-circle',
'permission' => 'access CiviCRM',
'operator' => 'OR',
'separator' => 0,
));
_mods_civix_insert_navigation_menu($menu, 'my_contact', array(
'label' => E::ts('My Contact in CiviCRM'),
'name' => 'my_contact_civicrm',
'url' => 'civicrm/me',
'permission' => 'access CiviCRM',
'operator' => 'OR',
'separator' => 0,
));
_mods_civix_insert_navigation_menu($menu, 'my_contact', array(
'label' => E::ts('My Contact in Drupal'),
'name' => 'my_contact_drupal',
'url' => 'user',
'permission' => 'access CiviCRM',
'operator' => 'OR',
'separator' => 0,
));
if (function_exists('statustracker_civicrm_config')) {
_mods_civix_insert_navigation_menu($menu, 'my_contact', array(
'label' => E::ts('My Processes'),
'name' => 'my_processes',
'url' => 'civicrm/statustracker/dashboard',
'permission' => 'access CiviCRM',
'operator' => 'OR',
'separator' => 0,
));
}
// add paper form link
_mods_civix_insert_navigation_menu($menu, 'Memberships', array(
'label' => E::ts('Paper Form'),
'name' => 'membership_paperform',
'url' => 'civicrm/member/paperform',
'permission' => 'edit memberships',
'operator' => 'OR',
'separator' => 0,
));
_mods_civix_navigationMenu($menu);
}
/**
* Implements hook_civicrm_buildForm().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_buildForm
*/
function mods_civicrm_buildForm($formName, &$form) {
if ($formName == 'CRM_Contact_Form_Merge') {
// see PV-7858
CRM_Core_Resources::singleton()->addScriptFile('com.proveg.mods', 'js/merge_mods.js');
}
}
/**
* Implements hook_civicrm_postProcess().
* @param $formName
* @param $form
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_postProcess/
*/
function mods_civicrm_postProcess($formName, &$form) {
switch ($formName) {
case 'CRM_Profile_Form_Edit':
$logger = new CRM_Mods_SubscriptionLogger();
$logger->log_subscription($form);
break;
default:
return;
}
}
/**
* Implements mods_civicrm_gdprx_postConsent().
*
* @see https://github.com/systopia/de.systopia.gdprx/issues/9
*/
function mods_civicrm_gdprx_postConsent($mode, $contact_id, $record_id, $data) {
CRM_Mods_Gdpr::updatePrivacySettings($contact_id);
}
/**
* Implements hook_civicrm_apiWrappers
*/
function mods_civicrm_apiWrappers(&$wrappers, $apiRequest) {
if ($apiRequest['entity'] == 'SepaMandate'
&& in_array($apiRequest['action'], ['create', 'createfull'])) {
$wrappers[] = new CRM_Mods_InternationalMandateWrapper();
}
if ($apiRequest['entity'] == 'MailingEventConfirm' && $apiRequest['action'] == 'create') {
$wrappers[] = new CRM_Mods_MailingEventConfirmWrapper();
}
}
/**
* Implements hook_civicrm_pre
*/
function mods_civicrm_pre($op, $objectName, $id, &$params) {
// Issue a warning if somebody edits a contact with an active membership
if ((!empty($id) && $op == 'edit') &&
($objectName == 'Individual' || $objectName == 'Organization' || $objectName == 'Household')) {
CRM_Mods_CardTitle::showCardTitleShouldBeAdjustedWarning($id, $params);
}
}
/**
* Implements hook_civicrm_post
*/
function mods_civicrm_post($op, $objectName, $objectId, &$objectRef) {
if ($op == 'create' && $objectName == 'Membership') {
// make sure we don't cause a recursion
static $disable_card_title_update = false;
if ($disable_card_title_update) return;
// make sure the card title field is there
$CUSTOM_FIELD_ID = CRM_Mods_CardTitle::getCardTitleFieldID();
if (!$CUSTOM_FIELD_ID) return;
$title_field = "custom_{$CUSTOM_FIELD_ID}";
// check if it's empty and
try {
$membership = civicrm_api3('Membership', 'getsingle', [
'id' => $objectId,
'return' => "{$title_field},id,contact_id"
]);
// if field is empty -> calculate new value
if (empty($membership[$title_field])) {
$field_list = ['formal_title','first_name','last_name'];
$contact = civicrm_api3('Contact', 'getsingle', [
'id' => $membership['contact_id'],
'return' => implode(',', $field_list) . ',contact_type,display_name']);
$pieces = [];
if ($contact['contact_type'] == 'Individual') {
foreach ($field_list as $field) {
if (!empty($contact[$field])) {
$pieces[] = $contact[$field];
}
}
} else {
$pieces[] = $contact['display_name'];
}
// set new title
$disable_card_title_update = true;
civicrm_api3('Membership', 'create', [
'id' => $objectId,
$title_field => trim(implode(' ', $pieces))
]);
}
} catch (Exception $ex) {
// something went wrong
Civi::log()->debug("mods: Error while setting ProVeg Card Title: " . $ex->getMessage());
}
}
}