function merci_staff_form_alter in MERCI (Manage Equipment Reservations, Checkout and Inventory) 6.2
Same name and namespace in other branches
- 8.2 modules/merci_staff/merci_staff.module \merci_staff_form_alter()
- 7.2 modules/merci_staff/merci_staff.module \merci_staff_form_alter()
File
- modules/
merci_staff/ merci_staff.module, line 50 - merci_staff functions
Code
function merci_staff_form_alter(&$form, $form_state, $form_id) {
if ($form_id != 'merci_reservation_node_form') {
return;
}
if (isset($form_state['node'])) {
$node = $form_state['node'] + (array) $form['#node'];
}
else {
$node = $form['#node'];
}
$node = (object) $node;
// Override the validation function so we can validate as the submitted user.
$form['#merci_staff_validated'][] = 'merci_node_validate';
$form['#validate'][] = 'merci_staff_node_validate';
foreach ($form['#merci_staff_validated'] as $function) {
$key = array_search($function, $form['#validate']);
if (is_numeric($key)) {
unset($form['#validate'][$key]);
}
}
// Recreate the groups and choices based on the submitted name.
merci_staff_user_load((array) $node);
if (module_exists('og')) {
og_form_add_og_audience($form, $form_state);
}
// Add the current choices to the form.
$reset = true;
foreach (element_children($form['choice_wrapper']['merci_reservation_items']) as $delta) {
if (is_numeric($delta)) {
continue;
}
$delta = substr($delta, 7);
$default = isset($node->merci_reservation_items["choice_" . $delta]['merci_item_nid']) ? $node->merci_reservation_items["choice_" . $delta]['merci_item_nid'] : '';
$form['choice_wrapper']['merci_reservation_items']["choice_" . $delta]['merci_item_nid'] = _merci_choice_form($node, $form_state, $delta, $default, $reset);
$reset = NULL;
}
merci_staff_user_load();
return $form;
}