You are here

function bat_fullcalendar_event_manager_form in Booking and Availability Management Tools for Drupal 7

The Event Manager Form.

1 string reference to 'bat_fullcalendar_event_manager_form'
bat_fullcalendar_bat_fullcalendar_modal_content in modules/bat_fullcalendar/bat_fullcalendar.module
Implements hook_bat_fullcalendar_modal_content().

File

modules/bat_fullcalendar/bat_fullcalendar.module, line 176
Manages the display of FullCalendar and provides ways for other modules to easily modify it.

Code

function bat_fullcalendar_event_manager_form($form, &$form_state, $entity_id, $event_type, $event_id, $start_date, $end_date) {
  $form = array();
  $new_event_id = $event_id;
  if (isset($form_state['values']['change_event_status'])) {
    $new_event_id = $form_state['values']['change_event_status'];
  }
  $form['#attributes']['class'][] = 'bat-management-form bat-event-form';

  // This entire form element will be replaced whenever 'changethis' is updated.
  $form['#prefix'] = '<div id="replace_textfield_div">';
  $form['#suffix'] = '</div>';
  $form['entity_id'] = array(
    '#type' => 'hidden',
    '#value' => $entity_id,
  );
  $form['event_type'] = array(
    '#type' => 'hidden',
    '#value' => $event_type->type,
  );
  $form['event_id'] = array(
    '#type' => 'hidden',
    '#value' => $event_id,
  );
  $form['bat_start_date'] = array(
    '#type' => 'hidden',
    '#value' => $start_date,
  );
  $form['bat_end_date'] = array(
    '#type' => 'hidden',
    '#value' => $end_date,
  );
  $unit = entity_load_single($event_type->target_entity_type, $entity_id);
  $form['event_title'] = array(
    '#prefix' => '<h2>',
    '#markup' => t('@unit_name', array(
      '@unit_name' => $unit->name,
    )),
    '#suffix' => '</h2>',
  );
  $date_format = variable_get('bat_date_format', 'Y-m-d H:i');
  $form['event_details'] = array(
    '#prefix' => '<div class="event-details">',
    '#markup' => t('Date range selected: @startdate to @enddate', array(
      '@startdate' => $start_date
        ->format($date_format),
      '@enddate' => $end_date
        ->format($date_format),
    )),
    '#suffix' => '</div>',
  );
  if ($event_type->fixed_event_states) {
    $state_options = bat_unit_state_options($event_type->type);
    $form['change_event_status'] = array(
      '#title' => t('Change the state for this event to') . ': ',
      '#type' => 'select',
      '#options' => $state_options,
      '#ajax' => array(
        'callback' => 'bat_fullcalendar_ajax_event_status_change',
        'wrapper' => 'replace_textfield_div',
      ),
      '#empty_option' => t('- Select -'),
    );
  }
  else {
    if (isset($event_type->default_event_value_field_ids[$event_type->type])) {
      $field_name = $event_type->default_event_value_field_ids[$event_type->type];
      $form['field_name'] = array(
        '#type' => 'hidden',
        '#value' => $field_name,
      );
      $field = field_info_field($field_name);
      $instance = field_info_instance('bat_event', $field_name, $event_type->type);
      $element = array(
        '#parents' => array(),
      );
      $widget = field_default_form('bat_event', NULL, $field, $instance, LANGUAGE_NONE, NULL, $element, $form_state);
      $form[$field_name] = $widget[$field_name];
      $form[$field_name]['#weight'] = 1;
      $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Update value'),
        '#weight' => 2,
        '#ajax' => array(
          'callback' => 'bat_fullcalendar_event_manager_form_ajax_submit',
          'wrapper' => 'replace_textfield_div',
        ),
      );
    }
  }
  return $form;
}