function availability_calendar_booking_formlet_form in Availability Calendars 7.3
Same name and namespace in other branches
- 7.5 booking_formlet/availability_calendar_booking_formlet.module \availability_calendar_booking_formlet_form()
- 7.4 booking_formlet/availability_calendar_booking_formlet.module \availability_calendar_booking_formlet_form()
1 string reference to 'availability_calendar_booking_formlet_form'
File
- booking_formlet/
availability_calendar_booking_formlet.module, line 467 - Availability Calendar booking formlet module. This submdule of the Availability Calendar module defines a field that shows a small booking form that interacts with a calendar field. The form only has an arraival and departure date field and a submit…
Code
function availability_calendar_booking_formlet_form($form_id, $form_state) {
static $formlet_count = 0;
module_load_include('inc', 'availability_calendar', 'availability_calendar');
$formlet_count++;
$entity_type = $form_state['build_info']['args'][0];
$entity = $form_state['build_info']['args'][1];
$entity_id = entity_extract_ids($entity_type, $entity);
$entity_id = $entity_id[0];
$entity_label = entity_label($entity_type, $entity);
$settings = $form_state['build_info']['args'][2];
$cids = $form_state['build_info']['args'][3];
$calendar = $form_state['build_info']['args'][4];
$calendar_settings = $form_state['build_info']['args'][5];
$from = $form_state['build_info']['args'][6];
$to = $form_state['build_info']['args'][7];
$form = array();
$form['#id'] = "availability-calendar-booking-formlet-form-{$formlet_count}";
$form['cid'] = array(
'#type' => 'hidden',
'#value' => $calendar !== NULL ? $calendar['cid'] : '',
);
$form['calendar_label'] = array(
'#type' => 'hidden',
'#value' => $calendar !== NULL ? $calendar['name'] : '',
);
$form['entity_type'] = array(
'#type' => 'hidden',
'#value' => $entity_type,
);
$form['entity_id'] = array(
'#type' => 'hidden',
'#value' => $entity_id,
);
$form['entity_label'] = array(
'#type' => 'hidden',
'#value' => $entity_label,
);
$form['from_iso'] = array(
'#type' => 'hidden',
'#value' => !empty($from) ? $from
->format(AC_ISODATE) : '',
);
$form['to_iso'] = array(
'#type' => 'hidden',
'#value' => !empty($to) ? $to
->format(AC_ISODATE) : '',
);
if ($settings['submit_only']) {
$form['from_display'] = array(
'#type' => 'hidden',
'#value' => $from instanceof DateTime ? availability_calendar_format_display_date($from) : '',
);
$form['to_display'] = array(
'#type' => 'hidden',
'#value' => $to instanceof DateTime ? availability_calendar_format_display_date($to) : '',
);
}
else {
$form['from_display'] = array(
'#type' => 'textfield',
'#title' => t('Arrival date'),
'#default_value' => $from instanceof DateTime ? availability_calendar_format_display_date($from) : '',
'#required' => TRUE,
'#disabled' => TRUE,
'#attributes' => array(
'readonly' => 'readonly',
),
'#prefix' => '<div class="acbf-date">',
'#suffix' => '<input class="acbf-reset-from form-reset" type="reset" value="' . t('Clear selected arrival date') . '" /></div>',
);
if ($settings['single_day_only']) {
$form['to_display'] = array(
'#type' => 'hidden',
'#value' => $to instanceof DateTime ? availability_calendar_format_display_date($to) : '',
);
$form['from_display']['#suffix'] = '<input class="acbf-reset-from form-reset" type="reset" value="' . t('Clear selected date') . '" /></div>';
}
else {
$form['to_display'] = array(
'#type' => 'textfield',
'#title' => t('Departure date'),
'#default_value' => $to instanceof DateTime ? availability_calendar_format_display_date($to) : '',
'#required' => TRUE,
'#disabled' => TRUE,
'#attributes' => array(
'readonly' => 'readonly',
),
'#prefix' => '<div class="acbf-date">',
'#suffix' => '<input class="acbf-reset-both form-reset" type="reset" value="' . t('Clear selected dates') . '" /></div>',
);
}
}
// Add form submit button.
$form['actions'] = array(
'#type' => 'actions',
'submit' => array(
'#type' => 'submit',
'#value' => t('Book this resource ...'),
'#disabled' => TRUE,
),
);
global $language;
$post_url = '';
if ($settings['define_per_language'] && isset($settings['post_url'][$language->language])) {
$post_url = $settings['post_url'][$language->language];
}
else {
if (isset($settings['post_url'][LANGUAGE_NONE])) {
$post_url = $settings['post_url'][LANGUAGE_NONE];
}
else {
if (is_array($settings['post_url'])) {
$post_url = reset($settings['post_url']);
}
}
}
if (is_array($post_url)) {
$post_url = reset($post_url);
}
$form['#action'] = url($post_url);
$form['#method'] = 'POST';
// Add js and css.
if ($settings['submit_only'] && $calendar !== NULL && $calendar_settings !== NULL) {
// If only the book now button is shown, the calendar might not be shown.
// Make sure there is a javascript instance that represents the selected
// calendar (and that can be queried by our javascript).
availability_calendar_add_calendar_js($calendar['cid'], $calendar['name'], $calendar_settings['allocation_type']);
}
availability_calendar_booking_formlet_add_js($formlet_count, $form['#id'], $cids, $settings);
$form['#attached']['css'] = array(
drupal_get_path('module', 'availability_calendar_booking_formlet') . '/availability_calendar_booking_formlet.css',
);
return $form;
}