-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patheventbuttonlabel.php
More file actions
264 lines (247 loc) · 8.63 KB
/
eventbuttonlabel.php
File metadata and controls
264 lines (247 loc) · 8.63 KB
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
<?php
require_once 'eventbuttonlabel.civix.php';
// phpcs:disable
use CRM_Eventbuttonlabel_ExtensionUtil as E;
// phpcs:enable
/**
* Implements hook_civicrm_config().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_config/
*/
function eventbuttonlabel_civicrm_config(&$config) {
_eventbuttonlabel_civix_civicrm_config($config);
}
/**
* Implements hook_civicrm_install().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_install
*/
function eventbuttonlabel_civicrm_install() {
_eventbuttonlabel_civix_civicrm_install();
}
/**
* Implements hook_civicrm_enable().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_enable
*/
function eventbuttonlabel_civicrm_enable() {
_eventbuttonlabel_civix_civicrm_enable();
}
/**
* Implements hook_civicrm_buildForm().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_buildForm
*/
function eventbuttonlabel_civicrm_buildForm($formName, &$form) {
if (in_array($formName, ['CRM_Event_Form_Registration_AdditionalParticipant', 'CRM_Event_Form_Registration_Register', 'CRM_Event_Form_Registration_Confirm'])) {
$hideMessages = _event_eventbuttonlabel_getButtonLabel($form->getVar('_eventId'), 'remove_status_msg');
if (is_bool($hideMessages) && !empty($hideMessages)) {
CRM_Core_Session::singleton()->getStatus(TRUE);
}
$buttons = &$form->getElement('buttons');
$isConfirmEnabled = TRUE;
$_name = $form->getVar('_name');
$participantNo = substr($_name, 12);
$values = [
'CRM_Event_Form_Registration_Confirm' => ['_qf_Confirm_next', 'confirm', $isConfirmEnabled],
'CRM_Event_Form_Registration_AdditionalParticipant' => ['_qf_Participant_' . $participantNo . '_next_skip', 'additional_skip_button', !$isConfirmEnabled],
'CRM_Event_Form_Registration_Register' => ['_qf_Register_upload', 'register', !$isConfirmEnabled],
];
foreach ($buttons->_elements as $index => &$elements) {
if ($elements->_attributes['name'] == $values[$formName][0]) {
$newButtonLabel = _event_eventbuttonlabel_getButtonLabel($form->getVar('_eventId'), $values[$formName][1]);
if (!is_bool($newButtonLabel) && !empty($newButtonLabel)) {
_event_eventbuttonlabel_updateButtonLabel($elements, $newButtonLabel, $values[$formName][2]);
}
if (is_bool($newButtonLabel) && !empty($newButtonLabel) && $values[$formName][1] == 'additional_skip_button') {
unset($buttons->_elements[$index]);
}
if ($values[$formName][2]) {
$form->assign('confirmButtonName', $newButtonLabel);
}
break;
}
}
if ($formName == 'CRM_Event_Form_Registration_Register' && !empty($form->_values['event']['is_multiple_registrations'])) {
$buttonLabel = _event_eventbuttonlabel_getButtonLabel($form->getVar('_eventId'), 'additional');
if (!empty($buttonLabel)) {
$form->assign('additional_buttonLabel', $buttonLabel);
$regularButtonLabel = _event_eventbuttonlabel_getButtonLabel($form->getVar('_eventId'), 'register');
$form->assign('regular_buttonLabel', $regularButtonLabel);
CRM_Core_Region::instance('page-body')->add([
'template' => 'CRM/Eventbuttonlabel/Additional.tpl',
]);
}
}
elseif ($formName == 'CRM_Event_Form_Registration_Confirm') {
CRM_Core_Region::instance('page-body')->add([
'template' => 'CRM/Eventbuttonlabel/ButtonFile.tpl',
]);
}
}
}
/**
* Function to get button label.
*
* @param $eventID
* @param $pageName
* @return bool|mixed|string|void
*/
function _event_eventbuttonlabel_getButtonLabel($eventID, $pageName) {
try {
$labelName = civicrm_api4('Event', 'get', [
'select' => [
"eventbuttonlabel_cg_buttonlabel.eventbuttonlabel_cf_{$pageName}",
],
'where' => [
['id', '=', $eventID],
],
'checkPermissions' => FALSE,
], 0)["eventbuttonlabel_cg_buttonlabel.eventbuttonlabel_cf_{$pageName}"] ?? '';
if (is_bool($labelName) && !empty($labelName)) {
return TRUE;
}
return $labelName;
}
catch (Exception $e) {
}
}
/**
* Function to update button label.
*
* @param $element
* @param $labelName
* @param false $isConfirmEnabled
*/
function _event_eventbuttonlabel_updateButtonLabel(&$element, $labelName,
$isConfirmEnabled = FALSE) {
if (!property_exists($element, '_content')) {
$element->_attributes['value'] = $labelName;
}
else {
$element->_content = substr_replace($element->_content, $labelName, (strpos($element->_content, '/i> ') + 4));
}
if ($isConfirmEnabled) {
$element->_attributes['onclick'] = "return submitOnceLabel(this,'" . $pageName . "','" . ts('Processing') . "');";
}
}
/**
* Implements hook_civicrm_managed().
*
* Generate a list of entities to create/deactivate/delete when this module
* is installed, disabled, uninstalled.
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_managed
*/
function eventbuttonlabel_civicrm_managed(&$entities) {
$entities[] = [
'module' => 'eventbuttonlabel',
'name' => 'eventbuttonlabel_cg_buttonlabel',
'entity' => 'CustomGroup',
'update' => 'never',
'params' => [
'version' => 3,
'name' => 'eventbuttonlabel_cg_buttonlabel',
'title' => ts('Event Button Labels'),
'extends' => 'Event',
'style' => 'Inline',
'is_active' => TRUE,
'is_public' => FALSE,
'is_reserved' => 1,
'options' => ['match' => ['name']],
],
];
$entities[] = [
'module' => 'eventbuttonlabel',
'name' => 'eventbuttonlabel_cf_register',
'entity' => 'CustomField',
'update' => 'never',
'params' => [
'version' => 3,
'name' => 'eventbuttonlabel_cf_register',
'label' => ts('Register Page button Label'),
'help_post' => ts('Used when no additonal participant configured.'),
'data_type' => 'String',
'html_type' => 'Text',
'is_active' => TRUE,
'text_length' => 255,
'weight' => 1,
'option_type' => 0,
'custom_group_id' => 'eventbuttonlabel_cg_buttonlabel',
'options' => ['match' => ['name', 'custom_group_id']],
],
];
$entities[] = [
'module' => 'eventbuttonlabel',
'name' => 'eventbuttonlabel_cf_additional',
'entity' => 'CustomField',
'update' => 'never',
'params' => [
'version' => 3,
'name' => 'eventbuttonlabel_cf_additional',
'label' => ts('Register Page button Label when additional participant is selected'),
'help_post' => ts('When a user selects additional participants from the drop down then this label gets used.'),
'data_type' => 'String',
'html_type' => 'Text',
'is_active' => TRUE,
'text_length' => 255,
'weight' => 2,
'option_type' => 0,
'custom_group_id' => 'eventbuttonlabel_cg_buttonlabel',
'options' => ['match' => ['name', 'custom_group_id']],
],
];
$entities[] = [
'module' => 'eventbuttonlabel',
'name' => 'eventbuttonlabel_cf_confirm',
'entity' => 'CustomField',
'update' => 'never',
'params' => [
'version' => 3,
'name' => 'eventbuttonlabel_cf_confirm',
'label' => ts('Confirm Page Button Label'),
'data_type' => 'String',
'html_type' => 'Text',
'is_active' => TRUE,
'text_length' => 255,
'weight' => 3,
'option_type' => 0,
'custom_group_id' => 'eventbuttonlabel_cg_buttonlabel',
'options' => ['match' => ['name', 'custom_group_id']],
],
];
$entities[] = [
'module' => 'eventbuttonlabel',
'name' => 'eventbuttonlabel_cf_additional_skip_button',
'entity' => 'CustomField',
'update' => 'never',
'params' => [
'version' => 3,
'name' => 'eventbuttonlabel_cf_additional_skip_button',
'label' => ts('Additional Participant Remove Skip Participant button'),
'data_type' => 'Boolean',
'html_type' => 'Radio',
'is_active' => TRUE,
'weight' => 4,
'custom_group_id' => 'eventbuttonlabel_cg_buttonlabel',
'options' => ['match' => ['name', 'custom_group_id']],
],
];
$entities[] = [
'module' => 'eventbuttonlabel',
'name' => 'eventbuttonlabel_cf_remove_status_msg',
'entity' => 'CustomField',
'update' => 'never',
'params' => [
'version' => 3,
'name' => 'eventbuttonlabel_cf_remove_status_msg',
'label' => ts('Remove Status Messages appear during the registration process.'),
'data_type' => 'Boolean',
'html_type' => 'Radio',
'is_active' => TRUE,
'weight' => 5,
'custom_group_id' => 'eventbuttonlabel_cg_buttonlabel',
'options' => ['match' => ['name', 'custom_group_id']],
],
];
}