function rooms_unit_edit_form_submit in Rooms - Drupal Booking for Hotels, B&Bs and Vacation Rentals 7
Form API submit callback for the Unit form.
@todo remove hard-coded link
1 string reference to 'rooms_unit_edit_form_submit'
- rooms_unit_edit_form in modules/
rooms_unit/ rooms_unit.admin.inc - Form callback: create or edit a unit.
File
- modules/
rooms_unit/ rooms_unit.admin.inc, line 481 - Rooms editing UI.
Code
function rooms_unit_edit_form_submit(&$form, &$form_state) {
$units = array();
if ($form_state['rooms_unit']->unit_id == '') {
$multiple = $form_state['values']['multiple'];
$name = $form_state['values']['name'];
for ($i = 1; $i <= $multiple; $i++) {
$units[$i] = rooms_unit_create(array(
'type' => $form_state['rooms_unit']->type,
));
$form_state['rooms_unit'] = $units[$i];
if ($i > 1) {
$form_state['values']['name'] = $name . ' - ' . $i;
}
$units[$i] = entity_ui_controller('rooms_unit')
->entityFormSubmitBuildEntity($form, $form_state);
// Add in created and changed times.
$units[$i]->is_new = isset($units[$i]->is_new) ? $units[$i]->is_new : 0;
$units[$i]->changed = time();
}
}
else {
$units[0] = $form_state['rooms_unit'];
$units[0] = entity_ui_controller('rooms_unit')
->entityFormSubmitBuildEntity($form, $form_state);
$units[0]->changed = time();
}
foreach ($units as $unit) {
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('Bookable unit @name saved', array(
'@name' => $unit->name,
)));
}
}