-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmultiform.module
More file actions
140 lines (124 loc) · 3.4 KB
/
Copy pathmultiform.module
File metadata and controls
140 lines (124 loc) · 3.4 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
<?php
/**
* @file
* An example module demonstrating the CTools multistep form wizard
*
* @note
* For Capital Camp 2014
* Jeremy Gottwig & Miro Scarfiotti
* RepEquity.com
*
* @see
* Full module available at:
* https://github.com/jgottwig/ctools-wizard-example
*/
define('OBJECT_ID', 1); // Make it easier to identify object by defining ID here
/**
* Implements hook_menu()
*/
function multiform_menu() {
$items['multiform'] = array(
'title' => t('My Example Multipage Form'),
'page callback' => 'multiform_form_builder',
'access arguments' => array('view content'),
);
return $items;
}
/**
* Our multipage form setup function
*/
function multiform_form_builder($step = NULL) {
ctools_include('wizard'); // Used for multi-page forms
ctools_include('object-cache'); // Used to handle data storage for multi-page forms
/**
* The $form_info provides configuration options
* for the ctools wizard
*/
$form_info = array(
'id' => 'multiform_form',
'path' => 'multiform/%step',
'show trail' => TRUE,
'show back' => TRUE,
'show cancel' => TRUE,
'show return' => FALSE,
'cancel callback' => '_multiform_builder_cancel',
'finish callback' => '_multiform_builder_finish',
'next callback' => '_multiform_builder_next',
'next text' => t('Next'),
'back text' => t('Previous'),
'finish text' => t('Submit'),
'order' => array(
'step-1' => t('Step One'),
'step-2' => t('Step Two'),
'step-3' => t('Step Three'),
),
'forms' => array(
'step-1' => array(
'form id' => 'step_1_form',
'include' => drupal_get_path('module', 'multiform') . '/multiform.step_1.inc',
),
'step-2' => array(
'form id' => 'step_2_form',
'include' => drupal_get_path('module', 'multiform') . '/multiform.step_2.inc',
),
'step-3' => array(
'form id' => 'step_3_form',
'include' => drupal_get_path('module', 'multiform') . '/multiform.step_3.inc',
),
),
);
if (empty($step)) {
$step = 'step-1';
}
$object = _multiform_get_obj_cache(OBJECT_ID);
$form_state = array(
'object_id' => OBJECT_ID,
'object' => &$object,
);
return ctools_wizard_multistep_form($form_info, $step, $form_state);
}
/**
* Retrieve object-cache or create
*/
function _multiform_get_obj_cache($id) {
ctools_include('object-cache');
if (!$cache = ctools_object_cache_get('multiform', $id)) {
$cache = new stdClass();
$cache->locked = ctools_object_cache_test('multiform', $id);
}
return $cache;
}
/**
* Update the object
*/
function _multiform_update_obj_cache($id, $content) {
ctools_include('object-cache');
$cache = ctools_object_cache_set('multiform', $id, $content);
}
/**
* Next button callback
*/
function _multiform_builder_next(&$form_state) {
_multiform_update_obj_cache(OBJECT_ID, $form_state['object']);
}
/**
* Finished button callback
*/
function _multiform_builder_finish() {
_multiform_clear_obj_cache(OBJECT_ID);
}
/**
* Cancel button callback
*/
function _multiform_builder_cancel(&$form_state) {
// Note that we could do something with our $form_state if we wanted
_multiform_clear_obj_cache(OBJECT_ID);
}
/**
* Clear our object cache
*/
function _multiform_clear_obj_cache($id) {
ctools_include('object-cache');
ctools_object_cache_clear('multiform', $id);
// Anything else you want to do here?
}