-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathwebform.install
1480 lines (1379 loc) · 50.7 KB
/
webform.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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* @file
* Webform module install/schema hooks.
*/
/**
* Implements hook_schema().
*/
function webform_schema() {
$schema = array();
$schema['webform'] = array(
'description' => 'Table for storing additional properties for webform nodes.',
'fields' => array(
'nid' => array(
'description' => 'The node identifier of a webform.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'next_serial' => array(
'description' => 'The serial number to give to the next submission to this webform.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 1,
),
'confirmation' => array(
'description' => 'The confirmation message or URL displayed to the user after submitting a form.',
'type' => 'text',
'not null' => TRUE,
),
'confirmation_format' => array(
'description' => 'The {filter_format}.format of the confirmation message.',
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
),
'redirect_url' => array(
'description' => 'The URL a user is redirected to after submitting a form.',
'type' => 'varchar',
'length' => 2048,
'default' => '<confirmation>',
),
'status' => array(
'description' => 'Boolean value of a webform for open (1) or closed (0).',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 1,
),
'block' => array(
'description' => 'Boolean value for whether this form be available as a block.',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
'allow_draft' => array(
'description' => 'Boolean value for whether submissions to this form be saved as a draft.',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
'auto_save' => array(
'description' => 'Boolean value for whether submissions to this form should be auto-saved between pages.',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
'submit_notice' => array(
'description' => 'Boolean value for whether to show or hide the previous submissions notification.',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 1,
),
'confidential' => array(
'description' => 'Boolean value for whether to anonymize submissions.',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
'submit_text' => array(
'description' => 'The title of the submit button on the form.',
'type' => 'varchar',
'length' => 255,
),
'submit_limit' => array(
'description' => 'The number of submissions a single user is allowed to submit within an interval. -1 is unlimited.',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => -1,
),
'submit_interval' => array(
'description' => 'The amount of time in seconds that must pass before a user can submit another submission within the set limit.',
'type' => 'int',
'not null' => TRUE,
'default' => -1,
),
'total_submit_limit' => array(
'description' => 'The total number of submissions allowed within an interval. -1 is unlimited.',
'type' => 'int',
'not null' => TRUE,
'default' => -1,
),
'total_submit_interval' => array(
'description' => 'The amount of time in seconds that must pass before another submission can be submitted within the set limit.',
'type' => 'int',
'not null' => TRUE,
'default' => -1,
),
'progressbar_bar' => array(
'description' => 'Boolean value indicating if the bar should be shown as part of the progress bar.',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
'progressbar_page_number' => array(
'description' => 'Boolean value indicating if the page number should be shown as part of the progress bar.',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
'progressbar_percent' => array(
'description' => 'Boolean value indicating if the percentage complete should be shown as part of the progress bar.',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
'progressbar_pagebreak_labels' => array(
'description' => 'Boolean value indicating if the pagebreak labels should be included as part of the progress bar.',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
'progressbar_include_confirmation' => array(
'description' => 'Boolean value indicating if the confirmation page should count as a page in the progress bar.',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
'progressbar_label_first' => array(
'description' => 'Label for the first page of the progress bar.',
'type' => 'varchar',
'length' => 255,
),
'progressbar_label_confirmation' => array(
'description' => 'Label for the last page of the progress bar.',
'type' => 'varchar',
'length' => 255,
),
'preview' => array(
'description' => 'Boolean value indicating if this form includes a page for previewing the submission.',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
'preview_next_button_label' => array(
'description' => 'The text for the button that will proceed to the preview page.',
'type' => 'varchar',
'length' => 255,
),
'preview_prev_button_label' => array(
'description' => 'The text for the button to go backwards from the preview page.',
'type' => 'varchar',
'length' => 255,
),
'preview_title' => array(
'description' => 'The title of the preview page, as used by the progress bar.',
'type' => 'varchar',
'length' => 255,
),
'preview_message' => array(
'description' => 'Text shown on the preview page of the form.',
'type' => 'text',
'not null' => TRUE,
),
'preview_message_format' => array(
'description' => 'The {filter_format}.format of the preview page message.',
'type' => 'varchar',
'length' => 255,
),
'preview_excluded_components' => array(
'description' => 'Comma-separated list of component IDs that should not be included in this form\'s confirmation page.',
'type' => 'text',
'not null' => TRUE,
),
),
'primary key' => array('nid'),
);
$schema['webform_component'] = array(
'description' => 'Stores information about components for webform nodes.',
'fields' => array(
'nid' => array(
'description' => 'The node identifier of a webform.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'cid' => array(
'description' => 'The identifier for this component within this node, starts at 0 for each node.',
'type' => 'int',
'size' => 'small',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'pid' => array(
'description' => 'If this component has a parent fieldset, the cid of that component.',
'type' => 'int',
'size' => 'small',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'form_key' => array(
'description' => 'When the form is displayed and processed, this key can be used to reference the results.',
'type' => 'varchar',
'length' => 128,
),
'name' => array(
'description' => 'The label for this component.',
'type' => 'text',
'not null' => TRUE,
),
'type' => array(
'description' => 'The field type of this component (textfield, select, hidden, etc.).',
'type' => 'varchar',
'length' => 16,
),
'value' => array(
'description' => 'The default value of the component when displayed to the end-user.',
'type' => 'text',
'not null' => TRUE,
),
'extra' => array(
'description' => 'Additional information unique to the display or processing of this component.',
'type' => 'text',
'not null' => TRUE,
),
'required' => array(
'description' => 'Boolean flag for if this component is required.',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
'weight' => array(
'description' => 'Determines the position of this component in the form.',
'type' => 'int',
'size' => 'small',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('nid', 'cid'),
);
$schema['webform_conditional'] = array(
'description' => 'Holds information about conditional logic.',
'fields' => array(
'nid' => array(
'description' => 'The node identifier of a webform.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'rgid' => array(
'description' => 'The rule group identifier for this group of rules.',
'type' => 'int',
'size' => 'small',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'andor' => array(
'description' => 'Whether to AND or OR the actions in this group. All actions within the same rgid should have the same andor value.',
'type' => 'varchar',
'length' => 128,
),
'weight' => array(
'description' => 'Determines the position of this conditional compared to others.',
'type' => 'int',
'size' => 'small',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('nid', 'rgid'),
);
$schema['webform_conditional_rules'] = array(
'description' => 'Holds information about conditional logic.',
'fields' => array(
'nid' => array(
'description' => 'The node identifier of a webform.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'rgid' => array(
'description' => 'The rule group identifier for this group of rules.',
'type' => 'int',
'size' => 'small',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'rid' => array(
'description' => 'The rule identifier for this conditional rule.',
'type' => 'int',
'size' => 'small',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'source_type' => array(
'description' => 'The type of source on which the conditional is based. Currently always "component". Indicates what type of ID the "source" column contains.',
'type' => 'varchar',
'length' => 128,
),
'source' => array(
'description' => 'The component ID being used in this condition.',
'type' => 'int',
'size' => 'small',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'operator' => array(
'description' => 'Which operator (equal, contains, starts with, etc.) should be used for this comparison between the source and value?',
'type' => 'varchar',
'length' => 128,
),
'value' => array(
'description' => 'The value to be compared with source.',
'type' => 'text',
),
),
'primary key' => array('nid', 'rgid', 'rid'),
);
$schema['webform_conditional_actions'] = array(
'description' => 'Holds information about conditional actions.',
'fields' => array(
'nid' => array(
'description' => 'The node identifier of a webform.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'rgid' => array(
'description' => 'The rule group identifier for this group of rules.',
'type' => 'int',
'size' => 'small',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'aid' => array(
'description' => 'The rule identifier for this conditional action.',
'type' => 'int',
'size' => 'small',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'target_type' => array(
'description' => 'The type of target to be affected. Currently always "component". Indicates what type of ID the "target" column contains.',
'type' => 'varchar',
'length' => 128,
),
'target' => array(
'description' => 'The ID of the target to be affected. Typically a component ID.',
'type' => 'varchar',
'length' => 128,
),
'invert' => array(
'description' => 'If inverted, execute when rule(s) are false.',
'type' => 'int',
'size' => 'small',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'action' => array(
'description' => 'The action to be performed on the target.',
'type' => 'varchar',
'length' => 128,
),
'argument' => array(
'description' => 'Optional argument for action.',
'type' => 'text',
),
),
'primary key' => array('nid', 'rgid', 'aid'),
);
$schema['webform_emails'] = array(
'description' => 'Holds information regarding e-mails that should be sent upon submitting a webform',
'fields' => array(
'nid' => array(
'description' => 'The node identifier of a webform.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'eid' => array(
'description' => 'The e-mail identifier for this row\'s settings.',
'type' => 'int',
'unsigned' => TRUE,
'size' => 'small',
'not null' => TRUE,
'default' => 0,
),
'email' => array(
'description' => 'The e-mail address that will be sent to upon submission. This may be an e-mail address, the special key "default" or a numeric value. If a numeric value is used, the value of a component will be substituted on submission.',
'type' => 'text',
'not null' => FALSE,
),
'subject' => array(
'description' => 'The e-mail subject that will be used. This may be a string, the special key "default" or a numeric value. If a numeric value is used, the value of a component will be substituted on submission.',
'type' => 'text',
'not null' => FALSE,
),
'from_name' => array(
'description' => 'The e-mail "from" name that will be used. This may be a string, the special key "default" or a numeric value. If a numeric value is used, the value of a component will be substituted on submission.',
'type' => 'text',
'not null' => FALSE,
),
'from_address' => array(
'description' => 'The e-mail "from" e-mail address that will be used. This may be a string, the special key "default" or a numeric value. If a numeric value is used, the value of a component will be substituted on submission.',
'type' => 'text',
'not null' => FALSE,
),
'template' => array(
'description' => 'A template that will be used for the sent e-mail. This may be a string or the special key "default", which will use the template provided by the theming layer.',
'type' => 'text',
'not null' => FALSE,
),
'excluded_components' => array(
'description' => 'A list of components that will not be included in the [submission:values] token. A list of CIDs separated by commas.',
'type' => 'text',
'not null' => TRUE,
),
'html' => array(
'description' => 'Determines if the e-mail will be sent in an HTML format. Requires Mime Mail module.',
'type' => 'int',
'unsigned' => TRUE,
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
'attachments' => array(
'description' => 'Determines if the e-mail will include file attachments. Requires Mime Mail module.',
'type' => 'int',
'unsigned' => TRUE,
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
'exclude_empty' => array(
'description' => 'Determines if the e-mail will include component with an empty value.',
'type' => 'int',
'unsigned' => TRUE,
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
'extra' => array(
'description' => 'A serialized array of additional options for the e-mail configuration, including value mapping for the TO and FROM addresses for select lists.',
'type' => 'text',
'not null' => TRUE,
),
'status' => array(
'description' => 'Whether this email is enabled.',
'type' => 'int',
'unsigned' => TRUE,
'size' => 'tiny',
'not null' => TRUE,
'default' => 1,
),
),
'primary key' => array('nid', 'eid'),
);
$schema['webform_roles'] = array(
'description' => 'Holds access information regarding which roles are allowed to submit which webform nodes. Does not prevent access to the webform node entirely, use the {node_access} table for that purpose.',
'fields' => array(
'nid' => array(
'description' => 'The node identifier of a webform.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'role' => array(
'type' => 'varchar',
'length' => 64,
'description' => 'Primary Key: The name of the role.',
'not null' => TRUE,
'default' => 'anonymous',
),
),
'primary key' => array('nid', 'role'),
);
$schema['webform_submissions'] = array(
'description' => 'Holds general information about submissions outside of field values.',
'fields' => array(
'sid' => array(
'description' => 'The unique identifier for this submission.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'nid' => array(
'description' => 'The node identifier of a webform.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'serial' => array(
'description' => 'The serial number of this submission.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'uid' => array(
'description' => 'The id of the user that completed this submission.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'is_draft' => array(
'description' => 'Is this a draft of the submission?',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
'highest_valid_page' => array(
'description' => 'For drafts, the highest validated page number.',
'type' => 'int',
'size' => 'small',
'not null' => TRUE,
'default' => 0,
),
'submitted' => array(
'description' => 'Timestamp when the form was first saved as draft or submitted.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'completed' => array(
'description' => 'Timestamp when the form was submitted as complete (not draft).',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'modified' => array(
'description' => 'Timestamp when the form was last saved (complete or draft).',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'remote_addr' => array(
'description' => 'The IP address of the user that submitted the form.',
'type' => 'varchar',
'length' => 128,
),
),
'primary key' => array('sid'),
'unique keys' => array(
'sid_nid' => array('sid', 'nid'),
'nid_serial' => array('nid', 'serial'),
),
'indexes' => array(
'nid_uid_sid' => array('nid', 'uid', 'sid'),
'nid_sid' => array('nid', 'sid'),
),
);
$schema['webform_submitted_data'] = array(
'description' => 'Stores all submitted field data for webform submissions.',
'fields' => array(
'nid' => array(
'description' => 'The node identifier of a webform.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'sid' => array(
'description' => 'The unique identifier for this submission.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'cid' => array(
'description' => 'The identifier for this component within this node, starts at 0 for each node.',
'type' => 'int',
'size' => 'small',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'no' => array(
'description' => 'Usually this value is 0, but if a field has multiple values (such as a time or date), it may require multiple rows in the database.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '0',
),
'data' => array(
'description' => 'The submitted value of this field, may be serialized for some components.',
'type' => 'text',
'size' => 'medium',
'not null' => TRUE,
),
),
'primary key' => array('nid', 'sid', 'cid', 'no'),
'indexes' => array(
'nid' => array('nid'),
'sid_nid' => array('sid', 'nid'),
// For all but MS SQL Server databases, 64-character index is created on
// the data column after the schema is installed.
),
);
$schema['webform_last_download'] = array(
'description' => 'Stores last submission number per user download.',
'fields' => array(
'nid' => array(
'description' => 'The node identifier of a webform.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'uid' => array(
'description' => 'The user identifier.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'sid' => array(
'description' => 'The last downloaded submission number.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'requested' => array(
'description' => 'Timestamp of last download request.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('nid', 'uid'),
);
return $schema;
}
/**
* Implements hook_requirements().
*/
function webform_requirements($phase) {
$requirements = array();
$t = get_t();
// Ensure cURL exists if SimpleTest hasn't checked it already.
if (!class_exists('ZipArchive')) {
$requirements['webform_zip'] = array(
'title' => $t('Zip archive support'),
'value' => $t('Missing'),
'severity' => REQUIREMENT_INFO,
'description' => $t('PHP does not have the zip archive extension available. Webform module requires zip support for exporting submissions to Microsoft Excel.'),
);
}
// Though the .info file specifies PHP version as well, this will prevent
// users from upgrading from 3.x if their PHP version is too old.
if (version_compare(phpversion(), '5.3') < 0) {
$requirements['webform_php'] = array(
'title' => $t('Webform PHP requirement'),
'value' => phpversion(),
'severity' => REQUIREMENT_ERROR,
'description' => $t('Webform requires PHP 5.3 or higher.'),
);
}
// Ensure that views is enabled as it is a new .info requirement starting
// with version 7.x-4.0rc1. On installation, the .info file is sufficient to
// cause the dependencies to be installed. On update, update.php will
// respect this hook_requirements implementation, but as of drush 6.3.0 and
// drush 7.0.0, drush updatedb will not. See:
// https://github.com/drush-ops/drush/issues/1427
if ($phase != 'install' && !module_exists('views')) {
$requirements['webform_views'] = array(
'title' => $t('Webform Views requirement'),
'value' => $t('Missing'),
'severity' => REQUIREMENT_ERROR,
'description' => $t('Webform requires Views, which is not installed and enabled.'),
);
}
return $requirements;
}
/**
* Implements hook_install().
*/
function webform_install() {
config_set('webform.settings', 'webform_default_from_name', config_get('system.core', 'site_name'));
config_set('webform.settings', 'webform_default_from_address', config_get('system.core', 'site_mail'));
module_load_include('inc', 'node', 'content_types');
db_update('system')
->condition('name', 'webform')
->condition('type', 'module')
->fields(array('weight' => -1))
->execute();
// Optionally create the default webform type.
if (config_get('webform.settings', 'webform_install_create_content_type')) {
$webform_type = array(
'type' => 'webform',
'name' => st('Webform'),
'base' => 'node_content',
'description' => st('Create a new form or questionnaire accessible to users. Submission results and statistics are recorded and accessible to privileged users.'),
'custom' => TRUE,
'modified' => TRUE,
'locked' => FALSE,
'settings' => array(
'comment_default' => '1', // Disable comments by default on Webform nodes.
),
);
$webform_type = node_type_set_defaults($webform_type);
node_type_save($webform_type);
// Enable webform components by default on Webform nodes.
config_set('webform.settings', 'webform_node_webform', TRUE);
// Now that a webform node type has been created, reset the cache of the
// node types that support webforms. This is needed for tests which will
// create nodes in the same execution.
backdrop_static_reset('webform_node_types');
if (config_get('webform.settings', 'webform_install_add_body_field')) {
node_add_body_field($webform_type);
}
}
else {
config_set('webform.settings', 'webform_node_types_primary', array());
}
// Note: MS SQL Server does not support size-limited indexes and the column
// type (text) is too big to fit inside index size limits.
if (!db_index_exists('webform_submitted_data', 'data') && db_driver() != 'sqlsrv') {
db_add_index('webform_submitted_data', 'data', array(array('data', 64)));
}
}
/**
* Implements hook_uninstall().
*/
function webform_uninstall() {
// Delete uploaded files.
$filepath = file_build_uri('webform');
file_unmanaged_delete_recursive($filepath);
// Delete the content type "webform" if:
// 1. there are no existing nodes of type webform and
// 2. no additional fields have been defined for node type webform, beyond the
// default body field.
$query = new EntityFieldQuery();
$results = $query->entityCondition('entity_type', 'node')
->entityCondition('bundle', 'webform')
->range(0, 1)
->execute();
$instances = field_info_instances('node', 'webform');
unset($instances['body']);
if (!$results && !$instances) {
node_type_delete('webform');
backdrop_flush_all_caches();
}
// Remove views
// We need to be explicit so we don't remove a user's custom views.
$names = array(
'views.view.webform_results',
'views.view.webform_submissions',
'views.view.webform_webforms',
'views.view.webform_analysis'
);
foreach ($names as $config_name) {
$config = config($config_name);
$config->delete();
}
// Clear admin bar cache to remove views from menu
cache('admin_bar')->flush();
}
/**
* Set the minimum upgrade version.
*
* Ensure you've upgraded to the 7.x-4.x version of webform in Drupal 7 before
* attempting to upgrade to Backdrop.
*/
function webform_update_last_removed() {
return 7421;
}
/**
* Update webforms from Drupal to Backdrop.
*/
function webform_update_1000() {
$config = config('webform.settings');
// migrate variables
$config->set('webform_install_create_content_type', update_variable_get('webform_install_create_content_type', TRUE));
$config->set('webform_install_add_body_field', update_variable_get('webform_install_add_body_field', FALSE));
$config->set('webform_node_webform', update_variable_get('webform_node_webform',TRUE));
$config->set('webform_blocks', update_variable_get('webform_blocks', array()));
$config->set('webform_tracking_mode', update_variable_get('webform_tracking_mode', 'cookie'));
$config->set('webform_allowed_tags', update_variable_get('webform_allowed_tags', array('a', 'em', 'strong', 'code', 'img')));
$config->set('webform_email_address_format', update_variable_get('webform_email_address_format', 'long'));
$config->set('webform_default_from_name', update_variable_get('webform_default_from_name', config_get('system.core', 'site_name')));
$config->set('webform_default_from_address', update_variable_get('webform_default_from_address', config_get('system.core', 'site_mail')));
$config->set('webform_default_subject', update_variable_get('webform_default_subject', t('Form submission from: [node:title]')));
$config->set('webform_email_replyto', update_variable_get('webform_email_replyto', TRUE));
$config->set('webform_email_html_capable', update_variable_get('webform_email_html_capable', FALSE));
$config->set('webform_default_format', update_variable_get('webform_default_format', 0));
$config->set('webform_format_override', update_variable_get('webform_format_override', 0));
$config->set('webform_email_select_max', update_variable_get('webform_email_select_max', 50));
$config->set('webform_node_types_primary', update_variable_get('webform_node_types_primary', array('webform')));
$config->set('webform_export_format', update_variable_get('webform_export_format', 'excel'));
$config->set('webform_csv_delimiter', update_variable_get('webform_csv_delimiter', '\t'));
$config->set('webform_export_wordwrap', update_variable_get('webform_export_wordwrap', 0));
$config->set('webform_excel_legacy_exporter', update_variable_get('webform_excel_legacy_exporter', 0));
$config->set('webform_progressbar_style', update_variable_get('webform_progressbar_style', array('progressbar_bar', 'progressbar_pagebreak_labels', 'progressbar_include_confirmation')));
$config->set('webform_progressbar_label_first', update_variable_get('webform_progressbar_label_first', t('Start')));
$config->set('webform_progressbar_label_confirmation', update_variable_get('webform_progressbar_label_confirmation', t('Complete')));
$config->set('webform_table', update_variable_get('webform_table', FALSE));
$config->set('webform_submission_access_control', update_variable_get('webform_submission_access_control', 1));
$config->set('webform_update_batch_size', update_variable_get('webform_update_batch_size', 100));
$config->set('webform_disabled_components', update_variable_get('webform_disabled_components', array()));
$config->set('webform_export_batch_size', update_variable_get('webform_export_batch_size', ''));
$config->set('webform_export_path', update_variable_get('webform_export_path', 'temporary://'));
$config->save();
// Delete variables.
update_variable_del('webform_install_create_content_type');
update_variable_del('webform_install_add_body_field');
update_variable_del('webform_node_webform');
update_variable_del('webform_blocks');
update_variable_del('webform_tracking_mode');
update_variable_del('webform_allowed_tags');
update_variable_del('webform_email_address_format');
update_variable_del('webform_default_from_name');
update_variable_del('webform_default_from_address');
update_variable_del('webform_default_subject');
update_variable_del('webform_email_replyto');
update_variable_del('webform_email_html_capable');
update_variable_del('webform_default_format');
update_variable_del('webform_format_override');
update_variable_del('webform_email_select_max');
update_variable_del('webform_node_types_primary');
update_variable_del('webform_export_format');
update_variable_del('webform_csv_delimiter');
update_variable_del('webform_export_wordwrap');
update_variable_del('webform_excel_legacy_exporter');
update_variable_del('webform_progressbar_style');
update_variable_del('webform_progressbar_label_first');
update_variable_del('webform_progressbar_label_confirmation');
update_variable_del('webform_table');
update_variable_del('webform_submission_access_control');
update_variable_del('webform_update_batch_size');
update_variable_del('webform_disabled_components');
update_variable_del('webform_use_cookies');
update_variable_del('webform_export_batch_size');
update_variable_del('webform_export_path');
}
/**
* Update webform_roles table
*/
function webform_update_1001() {
db_drop_primary_key('webform_roles');
db_change_field('webform_roles', 'rid', 'rid',
array(
'description' => 'The role identifier.',
'type' => 'varchar',
'length' => 16,
'not null' => TRUE,
'default' => 'anonymous',
),
array('primary key' => array('nid', 'rid')));
}
/**
* Remove the administrator option "Include webform forms in search index" and rely on the Search Index view mode instead.
*/
function webform_update_1002() {
$config = config('webform.settings');
$config->clear('webform_search_index');
$config->save();
return module_exists('search')
? t('Webform forms will now be included in the search index only if the Webform "field" is displayed in the "Search index" view mode.')
: NULL;
}
/**
* Remove unused variables
*/
function webform_update_1003() {
$config = config('webform.settings');
$config->clear('comment_webform');
$config->clear('webform_use_cookies');
$config->save();
}
/**
* Create webform_webforms view if it doesn't exist already.
* Default webform to using the administrative views instead of tables.
*/
function webform_update_1004() {
$config = config('webform.settings');
$config->set('webform_table', FALSE);
$config->save();
// See if there is already a webform_webforms view on this site.
$config_webform = config('views.view.webform_webforms');
if ($config_webform->isNew()) {
// If not, create the new webform_webforms view.
$path = backdrop_get_path('module', 'webform') . '/config/';
$contents = file_get_contents($path . 'views.view.webform_webforms.json');
$data = json_decode($contents, true);
$config_webform->setData($data);
$config_webform->save();
}
}
/**
* Create webform_results view if it doesn't exist already.
*/
function webform_update_1005() {
// See if there is already a webform_results view on this site.
$config_results = config('views.view.webform_results');
if ($config_results->isNew()) {
// If not, create the new webform_webforms view.
$path = backdrop_get_path('module', 'webform') . '/config/';
$contents = file_get_contents($path . 'views.view.webform_results.json');
$data = json_decode($contents, true);
$config_results->setData($data);
$config_results->save();
}
}
/**
* Create webform_submissions views if it doesn't exist already.
*/
function webform_update_1006() {