function merci_hours_date_popup_process_alter in MERCI (Manage Equipment Reservations, Checkout and Inventory) 7.3
Implements hook_date_popup_process_alter().
This function perform two tasks:
- adds an extra validation callback if a work calendar is set
- adds javascript settings to control the available days in the popup.
File
- merci_hours/
merci_hours.module, line 251
Code
function merci_hours_date_popup_process_alter(&$element, $form_state, $context) {
if (!array_key_exists('#instance', $element)) {
return;
}
$settings = $element['#instance']['settings']['merci_hours'];
if ($settings['enabled']) {
$element['#element_validate'][] = 'merci_hours_date_element_validate';
$merci_hours = variable_get('merci_hours_default', '');
// Current year. TODO: extend to a dinamic ajax callback.
// Limit selectable days based on days open.
$element['date']['#attributes']['class'][] = 'merci-hours-date-popup';
$id = $element['date']['#id'];
$settings = array(
$id => array(
'settings' => array(
'workCalendar' => $merci_hours,
'openDays' => merci_hours_get_open_days_in_year($merci_hours),
'minDate' => $settings['min_date'],
'maxDate' => $settings['max_date'],
'timeid' => $element['time']['#id'],
),
),
);
drupal_add_js(array(
'datePopup' => $settings,
), 'setting');
drupal_add_js(drupal_get_path('module', 'merci_hours') . '/merci_hours_date_popup.js');
// Limit selectable times based on hours open.
$return_id = $element['time']['#id'];
$open_hours = merci_hours_get_open_hours($merci_hours, 4);
$element['time']['#attributes']['class'][] = 'merci-hours-timefield';
$settings = array(
'minTime' => $open_hours['open'],
'maxTime' => $open_hours['close'],
'dateid' => $element['date']['#id'],
'workCalendar' => $merci_hours,
);
if (empty($element['time']['#value'])) {
$element['time']['#value'] = $open_hours['open'];
}
$js_settings['datePopup'][$return_id] = array(
'settings' => $settings,
);
drupal_add_js($js_settings, 'setting');
}
if (end($element['#parents']) == 'value2') {
$element['#states'] = array(
'visible' => array(
':input[name="set_merci_date"]' => array(
'value' => 'custom',
),
),
);
}
}