-
Notifications
You must be signed in to change notification settings - Fork 3
/
signup.api.php
292 lines (275 loc) · 10.8 KB
/
signup.api.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
285
286
287
288
289
290
291
292
<?php
// $Id: signup.api.php,v 1.5 2009/09/19 01:42:52 dww Exp $
/**
* @file
* This file documents the hooks invoked by the Signup module.
*/
/**
* Hook to define panes available to insert into the signup form.
*
* Panes should be provided by callback functions as a FormAPI array.
* The callback should have the following signature:
* function my_callback(&$signup_form, &$form_state, $node, $signup, $pane_id, $signup_type = 'auth')
* See signup_basic_form_form for an example.
* The values submitted to the form elements defined by this form will be
* serialized and stored in the {signup_log} table as 'form_data'.
*
* @param $node
* (optional) The node being considered for panes.
* Most modules won't need to look at this, but you may need to only return
* panes if the node satisfies certain properties.
*
* @return
* An array of possible forms, keyed by a unique ID. Each value is itself an
* array of data, with the following key-value pairs:
* - 'label': (required) The human-readable name of the form.
* - 'description': (required) Extra information about the form.
* - 'callback': (required) The name of a function.
* - 'operations': (optional) A list of links for the user to perform
* administrative tasks on this pane, either global or per-node settings.
* The format is an unkeyed array of link arrays (suitable for passing
* to theme_links).
* You may use %nid as a token in your link's href property to
* insert the node id of the current signup node.
* The following optional keys are also available:
* - destination: if set to TRUE, the return destination will be appended
* to the link as a query string with drupal_get_destination, allowing
* the user to return to this page directly. Do not use if your link
* sends the user to a complex series of forms or pages.
* - not_defaults: if set to TRUE, this link will not be shown when
* default signup settings are being edited at admin/settings/signup.
* Use this when your settings link would be meaningless in this
* context because it is dependent on the current node.
*
* @see signup_basic_form_form.
*/
function hook_signup_pane_info($node = NULL) {
return array(
'basic' => array(
'label' => 'Basic form',
'description' => 'Collects name and phone number.',
'callback' => 'signup_basic_form_form',
),
);
}
/**
* Hook to alter signup data before a signup is inserted or updated.
*
* @param $signup
* Reference to the fully-loaded signup object representing the signup.
* Modules implementing this hook may prevent a signup from going ahead by
* setting $signup->block_signup = TRUE.
* It is up to the implementing module to provide a message to the user to
* explain why their attempt to sign up has failed.
* @param $form_values
* Array of form values (if any) from the signup being inserted or updated.
*/
function hook_signup_data_alter(&$signup, $form_values) {
// TODO
}
/**
* Hook invoked when a signup is being canceled.
*
* At the time this hook is invoked the record about the signup in the
* {signup_log} table still exists, but the node has already had its signup
* total decremented.
*
* @param $node
* The fully-loaded node object that the signup is being canceled from.
* @param $signup
* An object containing all the known information about the signup being
* canceled. Contains all the data from the {signup_log} row representing
* the canceled signup. See the schema definition for descriptions of each
* field and what they represent.
*
* @return
* Ignored.
*
* @see signup_cancel_signup()
*/
function hook_signup_cancel($signup, $node) {
$info = array();
$info[] = t('Signup ID: @sid', array('@sid' => $signup->sid));
$info[] = t('Node ID: @nid', array('@nid' => $signup->nid));
$info[] = t('User ID: @uid', array('@uid' => $signup->uid));
$info[] = t('Email address for anonymous signup: @anon_mail', array('@anon_mail' => $signup->anon_mail));
$info[] = t('Date/time when the signup was created: @signup_time', array('@signup_time' => $signup->signup_time));
$form_data = unserialize($signup->form_data);
$info[] = t('Custom signup form data: %signup_form_data', array('%signup_form_data' => theme('signup_custom_data_email', $form_data)));
$info[] = t('Attendance record: %attended', array('%attended' => theme('signup_attended_text', $signup->attended)));
$info[] = t('Slots consumed by this signup: @count_towards_limit', array('@co
unt_towards_limit' => $signup->count_towards_limit));
drupal_set_message(theme('item_list', $info, t('Signup canceled for %node_title', array('%node_title' => $node->title))));
}
/**
* Hook invoked after a signup has been inserted.
*
* @param $signup
* The fully-loaded signup object representing the new signup.
*/
function hook_signup_insert($signup) {
// TODO
}
/**
* Hook invoked after a signup has been updated.
*
* @param $signup
* The fully-loaded signup object representing the updated signup.
*/
function hook_signup_update($signup) {
// TODO
}
/**
* Hook invoked when a signup is being created to gather other signup data.
*
* This hook allows other modules to inject information into the custom signup
* data for each signup. The array is merged with the values of any custom
* fields from hook_signup_pane_info(), serialized, and stored in the
* {signup_log} database table.
*
* @param $node
* Fully-loaded node object being signed up to.
* @param $account
* Full-loaded user object who is signing up.
*
* @return
* Keyed array of fields to include in the custom data for this signup. The
* keys for the array are used as labels when displaying the field, so they
* should be human-readable (and wrapped in t() to allow translation).
*
* @see signup_sign_up_user()
* @see hook_signup_pane_info()
*/
function hook_signup_sign_up($node, $account) {
return array(
t('Node type') => node_get_types('name', $node->type),
t('User created') => format_date($account->created),
);
}
/**
* Hook invoked whenever a node is reopened for signups.
*
* A node with signups closed could be reopened in two main cases: 1) someone
* cancels a signup and the signup limit is no longer reached; 2) a signup
* administrator manually re-opens signups.
*
* @param $node
* Fully-loaded node object that is now open for signups.
*
* @return
* Ignored.
*
* @see signup_open_signup()
*/
function hook_signup_open($node) {
drupal_set_message(t('Duplicate message: signups are now open on %title.', array('%title' => $node->title)));
}
/**
* Hook invoked whenever a node is closed for signups.
*
* Signups are closed in 3 main cases: 1) it is a time-based node and the
* close-in-advance time has been reached (auto-close via cron); 2) the node
* has a signup limit and the limit is reached; 3) a signup administrator
* manually closes signups.
*
* @param $node
* Fully-loaded node object that is now closed for signups.
*
* @return
* Ignored.
*
* @see signup_close_signup()
*/
function hook_signup_close($node) {
drupal_set_message(t('Duplicate message: signups are now closed on %title.', array('%title' => $node->title)));
}
/**
* Hook invoked to see if signup information should be printed for a node.
*
* This hook is invoked whenever someone is viewing a signup-enabled node and
* allows modules to suppress any signup-related output. If any module's
* implementation of this hook returns TRUE, no signup information will be
* printed for that node.
*
* @param $node
* The fully-loaded node object being viewed.
*
* @return
* TRUE if you want to prevent signup information from being printed, FALSE
* or NULL if the information should be printed.
*
* @see _signup_needs_output()
* @see _signup_menu_access()
* @see signup_nodeapi()
*/
function hook_signup_suppress($node) {
if ($node->nid % 2) {
drupal_set_message(t('Signup information suppressed for odd node ID %nid.', array('%nid' => $node->nid)));
return TRUE;
}
}
/**
* Hook invoked to control access to signup menu items.
*
* This hook is invoked to check access for signup menu items, in particular,
* the signup-related tabs on signup-enabled nodes. If no value is returned
* (NULL), the hook is ignored and the usual access logic is enforced via the
* Signup module. If multiple modules return a value, the logical OR is used,
* so if anyone returns TRUE, access is granted. If everyone returns FALSE,
* access is denied (even if the Signup module would normally grant access).
*
* @param $node
* The fully-loaded node object where the menu items would be attached.
* @param $menu_type
* String specifying what kind of menu item to test access for. Can be:
* 'signup': the signup form
* 'list': the signup attendee listing
* 'admin': the signup administration tab
* 'add': the signup administration tab to add other users (requires
* that signups are currently open on the given node).
* 'broadcast': for the broadcast tab
*
* @return
* TRUE if you want to allow access to the requested menu item, FALSE if you
* want to deny access (although if another hook implementation returns
* TRUE, that will take precedence), or NULL if you don't care and want to
* let Signup module itself decide access based on its own logic.
*
* @see _signup_menu_access()
*/
function hook_signup_menu_access($node, $menu_type) {
// For example, you might want to test that the current user is the
// administrator of the organic group that a signup-enabled node belongs to,
// in which case, you'd return TRUE here to give that user full signup
// powers over events in their group.
}
/**
* Implementation of hook_signup_form_data_display_alter().
*
* Allow modules to alter signup form data prior to displaying signup records
* in, for example, a node's list of signups at node/N/signups/admin.
*
* This allows modules that implement signup panes for format or even inject
* their own data.
*
* @param $form_data
* The user's signup data to alter.
* @param $nid
* The node id for the signup-enabled node.
* @param $sid
* The signup record id.
* @param $uid
* The user id whose signup this is; 0 if this is an anonymous signup.
* @param $type
* The type of output being prepared. Possible values are:
* - 'list': The hardcoded admin lists of signups, eg at node/X/signups/admin
* - 'view': The form data field in Views.
* - 'mail': Email output. This is likely the only one that needs special
* handling; in this case, modules should be more generous about supplying
* data since there's no other place to see it.
*/
function hook_signup_form_data_display_alter(&$form_data, $nid, $sid, $uid, $type = 'list') {
foreach ($form_data as $pane_id => $pane_data) {
// If this is one of your panes, do stuff to it.
}
}