function bat_event_edit_form_submit in Booking and Availability Management Tools for Drupal 7
Form API submit callback for the Event form.
1 string reference to 'bat_event_edit_form_submit'
- bat_event_edit_form in modules/
bat_event/ bat_event.admin.inc - Form callback: create or edit a event.
File
- modules/
bat_event/ bat_event.admin.inc, line 477 - Unit event editing UI.
Code
function bat_event_edit_form_submit(&$form, &$form_state) {
// We also need appropriate named variables for start and end date.
// It's simpler to do this than change all the other code for now.
$form_state['values']['start_date'] = $form_state['values']['bat_start_date'];
$form_state['values']['end_date'] = $form_state['values']['bat_end_date'];
// If we are dealing with a new event.
if ($form_state['bat_event']->event_id == '') {
$event = bat_event_create(array(
'type' => $form_state['bat_event']->type,
'start_date' => $form_state['values']['start_date'],
'end_date' => $form_state['values']['end_date'],
));
$form_state['bat_event'] = $event;
$event = entity_ui_controller('bat_event')
->entityFormSubmitBuildEntity($form, $form_state);
$event->is_new = isset($event->is_new) ? $event->is_new : 0;
}
else {
$event = entity_ui_controller('bat_event')
->entityFormSubmitBuildEntity($form, $form_state);
}
// Subtract one minute from the end date since BAT considers the last minute of an event included.
$end_date = new DateTime($event->end_date);
$end_date
->sub(new DateInterval('PT1M'));
$event->end_date = $end_date
->format('Y-m-d H:i');
// Add in created and changed times.
$event->created = !empty($event->date) ? strtotime($event->date) : REQUEST_TIME;
$event->changed = time();
// Add in the event owner.
if ($account = user_load_by_name($event->owner_name)) {
$event->uid = $account->uid;
}
else {
$event->uid = 0;
}
// Save event.
$event
->save();
// Add the event to $form_state to be altered by other submit handlers.
$form_state['event'] = $event;
$form_state['redirect'] = 'admin/bat/events';
}