You are here

function signup_edit_form in Signup 7

Same name and namespace in other branches
  1. 6.2 includes/signup_edit_form.inc \signup_edit_form()
  2. 6 includes/signup_edit_form.inc \signup_edit_form()

Build the form for editing existing signups.

Parameters

array $form: An associative array containing the structure of the form.

array $form_state: The state of the form to build (not currently used).

stdClass $signup: The fully-loaded signup object with data about the signup to edit.

string $type: The type of signup edit form to render, can be 'node', 'tab', or 'admin'.

Return value

array 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
Implements 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, &$form_state, $signup, $type) {
  global $user;
  $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(
      '#markup' => $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', array(
      'attended' => 1,
    ));
    $options[0] = theme('signup_attended_text', array(
      'attended' => 0,
    ));
    $form['elements']['attended'] = array(
      '#type' => 'select',
      '#title' => t('Attendance'),
      '#default_value' => isset($signup->attended) ? $signup->attended : -1,
      '#options' => $options,
    );
  }

  // Build the themed signup form for this site and include that.
  $site_form = theme('signup_user_form', array(
    'node' => $node,
  ));
  $form_data = unserialize($signup->form_data);

  // This is sort of a hack, but we don't support nested arrays for the custom
  // signup form anyway, so it works for now.  Obviously all this will change
  // with signup_fields and friends, but for now it works.
  foreach ($form_data as $key => $value) {
    if (!empty($site_form['signup_form_data'][$key])) {
      $site_form['signup_form_data'][$key]['#default_value'] = $value;
      if (!$can_edit) {

        // If they can't edit, mark all the fields as disabled.
        $site_form['signup_form_data'][$key]['#disabled'] = TRUE;
      }
    }
  }
  $form['elements'] += $site_form;

  // Add the appropriate buttons based on permissions, but do not display the
  // edit button, if there are no form elements to edit.
  if ($can_edit && !empty($site_form)) {
    $form['elements']['save'] = array(
      '#type' => 'submit',
      '#value' => t('Save'),
      '#submit' => array(
        'signup_edit_form_save_submit',
      ),
    );
  }
  if ($can_cancel) {
    if (isset($_GET['destination'])) {
      $destination = drupal_get_destination();
    }
    else {

      // If there's no destination already set, redirect to the node.
      $destination = array(
        'destination' => 'node/' . $signup->nid,
      );
    }
    $signup_token = signup_get_token($signup->sid, 'cancel');
    $form['elements']['cancel-signup'] = array(
      '#markup' => l(t('Cancel signup'), "signup/cancel/{$signup->sid}/{$signup_token}", array(
        'query' => $destination,
      )),
    );
  }
  return $form;
}