function signup_edit_form in Signup 6.2
Same name and namespace in other branches
- 6 includes/signup_edit_form.inc \signup_edit_form()
- 7 includes/signup_edit_form.inc \signup_edit_form()
Build the form for editing existing signups.
Parameters
$form_state: The state of the form to build (not currently used).
$signup: The fully-loaded signup object with data about the signup to edit.
$type: The type of signup edit form to render, can be 'node', 'tab', or 'admin'.
Return value
The FAPI form array for the signup edit form.
4 string references to 'signup_edit_form'
- signup_confirm_email_alter_signup_form in modules/
signup_confirm_email/ signup_confirm_email.inc - Alter the signup form to add the e-mail confirmation functionality.
- signup_confirm_email_form_alter in modules/
signup_confirm_email/ signup_confirm_email.module - Implement hook_form_alter().
- signup_edit_page in includes/
signup_edit_form.inc - Page handler for the administrator page to edit an existing signup.
- _signup_render_signup_edit_form in includes/
node_output.inc - Helper function to render the form to edit your own signup.
File
- includes/
signup_edit_form.inc, line 22 - Code for the form to edit existing signups.
Code
function signup_edit_form($form_state, $signup, $type) {
global $user;
$form = array();
$form['#signup'] = $signup;
$node = node_load($signup->nid);
// Check permissions.
$admin = _signup_menu_access($node, 'admin');
$own = !empty($user->uid) && $user->uid == $signup->uid;
$can_cancel = $admin || user_access('cancel own signups') && $own;
$can_edit = $admin || user_access('edit own signups') && $own;
if ($type == 'admin') {
$title = t("Information for !user's signup to !node", array(
'!user' => _signup_get_username($signup, TRUE),
'!node' => l($node->title, 'node/' . $node->nid),
));
}
else {
$title = t('Your signup information');
}
if ($type == 'node') {
$form['elements'] = array(
'#type' => 'fieldset',
'#title' => $title,
'#collapsible' => TRUE,
'#collapsed' => variable_get('signup_fieldset_collapsed', 1),
);
}
else {
$form['elements'] = array();
$form['elements']['header'] = array(
'#type' => 'markup',
'#value' => $title,
'#prefix' => '<h4>',
'#suffix' => '</h4>',
);
}
if (!empty($signup->anon_mail)) {
$form['elements']['signup_anon_mail'] = array(
'#type' => 'textfield',
'#title' => t('Email'),
'#default_value' => $signup->anon_mail,
'#size' => 40,
'#maxlength' => 255,
'#required' => TRUE,
);
$form['#validate'][] = 'signup_validate_anon_mail';
}
if ($admin) {
$options = array();
if (1 || !isset($signup->attended)) {
$options[-1] = t('- Not recorded -');
}
$options[1] = theme('signup_attended_text', 1);
$options[0] = theme('signup_attended_text', 0);
$form['elements']['attended'] = array(
'#type' => 'select',
'#title' => t('Attendance'),
'#default_value' => isset($signup->attended) ? $signup->attended : -1,
'#options' => $options,
);
}
// Build all the signup panes for this node.
if (isset($node->signup_form_panes)) {
$form['elements']['signup_form_data'] = array(
'#tree' => TRUE,
);
foreach (array_keys($node->signup_form_panes) as $pane_id) {
$callback = $node->signup_form_panes[$pane_id]['callback'];
if (function_exists($callback)) {
// Each pane goes into its own form element with #tree set
// to protect form values from clashing.
$form['elements']['signup_form_data'][$pane_id] = array(
'#tree' => TRUE,
);
// Add a validation function for each pane.
$form['elements']['signup_form_data']['#element_validate'][] = $callback . '_validate';
$form['elements']['signup_form_data'][$pane_id] += $callback($form, $form_state, $node, $signup, $pane_id, $signup_type);
}
}
}
$form_data = unserialize($signup->form_data);
// This is *still* sort of a hack, and means that nested arrays in signup
// form panes won't work.
// Does Drupal FormAPI provide a means to re-fill a $form array with values
// from a $form_values array? It really should.
foreach ($form_data as $pane_id => $pane_data) {
foreach ($pane_data as $key => $value) {
if (!empty($form['elements']['signup_form_data'][$pane_id][$key])) {
// The pane callback may have provided its own default values: if so
// then don't clobber them.
if (!isset($form['elements']['signup_form_data'][$pane_id][$key]['#default_value'])) {
$form['elements']['signup_form_data'][$pane_id][$key]['#default_value'] = $value;
}
}
}
}
// Add the appropriate buttons based on permissions.
if ($can_edit) {
$form['elements']['save'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#submit' => array(
'signup_edit_form_save_submit',
),
);
}
else {
// If they can't edit, mark all the fields as disabled.
_signup_form_element_disable_recursive($form['elements']['signup_form_data']);
}
if ($can_cancel) {
if (isset($_REQUEST['destination'])) {
$destination = drupal_get_destination();
}
else {
// If there's no destination already set, redirect to the node.
$destination = 'destination=' . urlencode("node/{$signup->nid}");
}
$signup_token = signup_get_token($signup->sid, 'cancel');
$form['elements']['cancel-signup'] = array(
'#type' => 'markup',
'#value' => l(t('Cancel signup'), "signup/cancel/{$signup->sid}/{$signup_token}", array(
'query' => $destination,
)),
);
}
return $form;
}