function bat_unit_edit_form_submit in Booking and Availability Management Tools for Drupal 7
Form API submit callback for the Unit form.
1 string reference to 'bat_unit_edit_form_submit'
- bat_unit_edit_form in modules/
bat_unit/ bat_unit.admin.inc - Form callback: create or edit a unit.
File
- modules/
bat_unit/ bat_unit.admin.inc, line 340 - BatUnit editing UI.
Code
function bat_unit_edit_form_submit(&$form, &$form_state) {
$units = array();
if ($form_state['bat_unit']->unit_id == '') {
$name = $form_state['values']['name'];
$unit = bat_unit_create(array(
'type' => $form_state['bat_unit']->type,
));
$form_state['bat_unit'] = $unit;
$unit = entity_ui_controller('bat_unit')
->entityFormSubmitBuildEntity($form, $form_state);
}
else {
$unit = $form_state['bat_unit'];
$unit = entity_ui_controller('bat_unit')
->entityFormSubmitBuildEntity($form, $form_state);
}
$unit->changed = time();
if (isset($unit->author_name)) {
if ($account = user_load_by_name($unit->author_name)) {
$unit->uid = $account->uid;
}
else {
$unit->uid = 0;
}
}
$unit->created = !empty($unit->date) ? strtotime($unit->date) : REQUEST_TIME;
$unit
->save();
drupal_set_message(t('Bat Unit @name saved', array(
'@name' => $unit->name,
)));
// If the form is being used in a views megarow, reload the page on
// submission.
if (strpos($form['#action'], '/display_megarow/') !== FALSE) {
ctools_include('ajax');
ctools_add_js('ajax-responder');
$commands = array();
$commands[] = ctools_ajax_command_reload();
print ajax_render($commands);
drupal_exit();
}
else {
$form_state['redirect'] = 'admin/bat/config/units';
}
}