-
Notifications
You must be signed in to change notification settings - Fork 0
/
amnistia_form_mobile.install
271 lines (259 loc) · 8.27 KB
/
amnistia_form_mobile.install
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
<?php
/**
* @file
* Implements installation schema for aministia form mobile.
*/
/**
* Implements hook_schema().
*/
function amnistia_form_mobile_schema() {
$schema = array();
$schema['amnistia_form_mobile'] = array(
'description' => 'Storage for amnistia form mobile',
'fields' => array(
'afme_id' => array(
'description' => 'Primary key: settings ID.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'email' => array(
'description' => 'eMail for lead has filled the form',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'token' => array(
'description' => 'Token for manage this element',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'form_id' => array(
'description' => 'Id webform for this element',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'data_serialized' => array(
'description' => 'Form data serialized. Used for refill the form.',
'type' => 'text',
'serialize' => TRUE,
),
'created' => array(
'description' => 'Creation date for this element (timestamp)',
'type' => 'int',
'not null' => TRUE,
),
'updated' => array(
'description' => 'Update date for this element (timestamp)',
'type' => 'int',
),
'status' => array(
'description' => 'Status for this element. 0: incompleted, 1: incompleted and remembered,2: completed',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
// Consider adding additional fields for time created, time updated.
),
'primary key' => array('afme_id'),
);
return $schema;
}
/**
* Implements hook_install().
*
* Add a return url field of link type, and 'mobile form' field to the Webform content type
*/
function amnistia_form_mobile_install() {
$fields = array(
array(
'name' => 'field_return_url',
'type' => 'link_field',
'label' => 'Return URL',
'description' => 'URL used to redirect the user once the form is filled',
'settings' => array(
'absolute_url' => 1,
'validate_url' => 1,
'url' => 0,
'title' => 'none',
'enable_tokens' => 0,
'rel_remove' => 'default',
'attributes' => array(
'target' => 'default',
'configurable_class' => 0,
'configurable_title' => 0,
)
)
),
array(
'name' => 'field_mobile_form',
'type' => 'list_boolean',
'label' => 'Mobile form',
'description' => 'Check if the form should be displayed with the mobile settings',
'settings' => array(
'allowed_values' => array(0, 1),
'validate_url' => 1,
'url' => 0,
'title' => 'none',
'enable_tokens' => 0,
'rel_remove' => 'default',
'attributes' => array(
'target' => 'default',
'configurable_class' => 0,
'configurable_title' => 0,
)
)
),
array(
'name' => 'field_time_remember',
'type' => 'list_text',
'label' => 'Remember in',
'description' => 'Select when the system should send an email to the user, if he did not complete the form.',
'settings' => array(
'allowed_values' => array(
'1800' => 'Half hour',
'3600' => '1 hour',
'14400' => '4 hours',
'43200' => '12 hours',
'86400' => '1 day',
'172800' => '2 day',
'345600' => '4 day',
'604800' => '1 week',
'1209600' => '2 weeks',
'2419200' => '4 weeks'
),
'attributes' => array(
'target' => 'default',
'configurable_class' => 0,
'configurable_title' => 0,
)
),
),
array(
'name' => 'field_email_reminder_subject',
'type' => 'text',
'label' => 'Email reminder Subject',
'settings' => array (),
'default_value' => array(
array('value' => '[Amnistia] Remember complete the form')
)
),
array(
'name' => 'field_email_reminder_from',
'type' => 'text',
'label' => 'Email reminder From',
'settings' => array (),
'default_value' => array(
array('value' => variable_get('site_mail', ''))
)
),
array(
'name' => 'field_email_reminder_content',
'type' => 'text_long',
'label' => 'Email reminder Content',
'description' => '[FORM_LINK text="here"] You can use this shortcode to generate a link to the this form.',
'format' => 'full_html',
'widget' => array(
'type' => 'text_textarea',
'format' => 'full_html'
),
'settings' => array(
'text_processing' => '1',
'format' => 'full_html',
),
'display' => array(
'format' => 'full_html',
'success_text' => array(
'label' => 'above',
'type' => 'text_default',
'format' => 'full_html',
),
)
)
);
// Create all fields on the $fields array
foreach($fields as $field) {
if(!field_info_field($field['name'])) {
// Create field
field_create_field(array(
'field_name' => $field['name'],
'type' => $field['type'],
'settings' => $field['settings'],
));
// Create instance
$instance = array(
'field_name' => $field['name'],
'entity_type' => 'node',
'bundle' => 'webform',
'label' => $field['label'],
'description' => $field['description'],
'required' => FALSE,
'settings' => $field['settings'],
'default_value' => $field['default_value']
);
if($field['name'] == 'field_mobile_form'){
$instance['widget'] = array(
'type' => 'options_onoff', // gives you a checkbox
'settings' => array(
'display_label' => 1, // uses 'My boolean checkbox' as the label next to the actual checkbox
)
);
}
field_create_instance($instance);
watchdog('amnistia_form_mobile', t('!field_name was added successfully.', array('!field_name' => $field['name'])));
} else {
watchdog('amnistia_form_mobile', t('!field_name already exists.', array('!field_name' => $field['name'])));
}
}
}
/**
* Implements hook_uninstall().
*
* Remove a return url field of link type, and 'mobile form' field to the Webform content type
*/
function amnistia_form_mobile_uninstall() {
$fields = array(
array(
'field_name' => 'field_return_url',
'entity_type' => 'node',
'bundle' => 'webform',
),
array(
'field_name' => 'field_mobile_form',
'entity_type' => 'node',
'bundle' => 'webform',
),
array(
'field_name' => 'field_time_remember',
'entity_type' => 'node',
'bundle' => 'webform',
),
array(
'field_name' => 'field_email_reminder_subject',
'entity_type' => 'node',
'bundle' => 'webform',
),
array(
'field_name' => 'field_email_reminder_from',
'entity_type' => 'node',
'bundle' => 'webform',
),
array(
'field_name' => 'field_email_reminder_content',
'entity_type' => 'node',
'bundle' => 'webform',
)
);
foreach ($fields as $field) {
if(!field_info_field($field['name'])) {
field_delete_instance($field);
field_delete_field($field['field_name']);
watchdog('amnistia_form_mobile', t('!field_name was removed successfully.', array('!field_name' => $field['field_name'])));
}
}
}