You are here

function merci_staff_form_alter in MERCI (Manage Equipment Reservations, Checkout and Inventory) 8.2

Same name and namespace in other branches
  1. 6.2 modules/merci_staff/merci_staff.module \merci_staff_form_alter()
  2. 7.2 modules/merci_staff/merci_staff.module \merci_staff_form_alter()

File

modules/merci_staff/merci_staff.module, line 47
merci_staff functions

Code

function merci_staff_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  return;
  if ($form_id != 'merci_reservation_node_form') {
    return;
  }
  if (!user_access('manage reservations')) {
    return;
  }
  if (isset($form_state['values'])) {
    $node = (array) $form_state['values'] + (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_reservation_node_validate';
  $form['#validate'][] = 'merci_staff_reservation_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_load_user((array) $node);

  // 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 = false;
  }
  merci_staff_load_user();
  array_push($form['field_merci_date']['field_merci_date_button']['#limit_validation_errors'], array(
    'name',
  ), array(
    'override',
  ));
  array_push($form['choice_wrapper']['merci_more']['#limit_validation_errors'], array(
    'name',
  ), array(
    'override',
  ));
  return $form;
}