'',
'form_key' => NULL,
'pid' => 0,
'weight' => 0,
'value' => '',
'mandatory' => 0,
'extra' => array(
'timezone' => 'user',
'hourformat' => '12-hour',
'title_display' => 0,
'description' => '',
),
);
}
/**
* Implementation of _webform_theme_component().
*/
function _webform_theme_time() {
return array(
'webform_time' => array(
'render element' => 'element',
),
'webform_display_time' => array(
'render element' => 'element',
),
);
}
/**
* Implementation of _webform_edit_component().
*/
function _webform_edit_time($component) {
$form = array();
$form['value'] = array(
'#type' => 'textfield',
'#title' => t('Default value'),
'#default_value' => $component['value'],
'#description' => t('The default value of the field.') . '
' . t('Accepts a time in any GNU Date Input Format. Strings such as now, +2 hours, and 10:30pm are all valid.'),
'#size' => 60,
'#maxlength' => 127,
'#weight' => 0,
);
$form['extra']['timezone'] = array(
'#type' => 'radios',
'#title' => t('Default value timezone'),
'#default_value' => empty($component['extra']['timezone']) ? 'user' : $component['extra']['timezone'],
'#description' => t('Adjust the default time value according to a specific timezone.'),
'#options' => array('user' => t('User timezone'), 'site' => t('Website timezone')),
'#weight' => -1,
'#access' => variable_get('configurable_timezones', 1),
);
$form['display']['hourformat'] = array(
'#type' => 'radios',
'#title' => t('Time Format'),
'#default_value' => isset($component['extra']['hourformat']) ? $component['extra']['hourformat'] : '12-hour',
'#description' => t('Format the display of the time in 12 or 24 hours.'),
'#options' => array('12-hour' => t('12-hour (am/pm)'), '24-hour' => t('24-hour')),
'#weight' => 2,
'#parents' => array('extra', 'hourformat'),
);
return $form;
}
/**
* Implementation of _webform_render_component().
*/
function _webform_render_time($component, $value = NULL, $filter = TRUE) {
$element = array(
'#title' => $filter ? _webform_filter_xss($component['name']) : $component['name'],
'#title_display' => $component['extra']['title_display'] ? $component['extra']['title_display'] : 'before',
'#required' => $component['mandatory'],
'#weight' => $component['weight'],
'#description' => $filter ? _webform_filter_descriptions($component['extra']['description']) : $component['extra']['description'],
'#element_validate' => array('webform_validate_time'),
'#hourformat' => $component['extra']['hourformat'],
'#after_build' => array('webform_expand_time'),
'#theme' => 'webform_time',
'#theme_wrappers' => array('webform_element'),
'#webform_component' => $component,
);
if (drupal_strlen($component['value']) > 0) {
// Adjust the time based on the user or site timezone.
if (variable_get('configurable_timezones', 1) && $component['extra']['timezone'] == 'user') {
$timezone_name = isset($GLOBALS['user']->timezone) ? $GLOBALS['user']->timezone : 'UTC';
}
else {
$timezone_name = variable_get('date_default_timezone', 'UTC');
}
$timezone = new DateTimeZone($timezone_name);
$datetime = new DateTime($component['value'], $timezone);
$default_values = webform_date_array($datetime->format('c'), 'time');
}
else {
$default_values = array(
'hour' => '',
'minute' => '',
'second' => '',
);
}
if (!empty($value[0])) {
$default_values = webform_date_array($value[0], 'time');
}
$first_hour = 0;
$last_hour = 23;
if ($component['extra']['hourformat'] == '12-hour') {
$first_hour = 1;
$last_hour = 12;
$default_values = webform_time_convert($default_values, '12-hour');
$default_values['ampm'] = $default_values['ampm'] ? $default_values['ampm'] : 'am';
}
// Generate the choices for drop-down selects.
$hours[''] = t('hour');
$minutes[''] = t('minute');
for ($i = $first_hour; $i <= $last_hour; $i++) $hours[$i] = $i;
for ($i = 0; $i <= 59; $i++) $minutes[$i] = $i < 10 ? "0$i" : $i;
$ampms = array('am' => t('am'), 'pm' => t('pm'));
$element['hour'] = array(
'#prefix' => '',
'#type' => 'select',
'#default_value' => $default_values['hour'],
'#options' => $hours,
);
$element['minute'] = array(
'#prefix' => ':',
'#type' => 'select',
'#default_value' => $default_values['minute'],
'#options' => $minutes,
);
if ($component['extra']['hourformat'] == '12-hour') {
$element['ampm'] = array(
'#type' => 'radios',
'#default_value' => $default_values['ampm'],
'#options' => $ampms,
);
}
// Set the overall default value.
if ($default_values['hour'] !== '') {
$element['#default_value'] = webform_date_string($default_values);
}
return $element;
}
/**
* Form API #after_build function for Webform time fields.
*
* Note that a #process function will not work on time fields, since they are
* not actual FAPI elements. We use this function to set the proper default
* values for the time fields.
*/
function webform_expand_time($element) {
if (array_key_exists('#default_value', $element)) {
$time_value = webform_date_array($element['#default_value'], 'time');
foreach ($time_value as $key => $value) {
$element[$key]['#value'] = $value;
}
}
return $element;
}
/**
* Theme a webform time element.
*/
function theme_webform_time($variables) {
$element = $variables['element'];
// Add error classes to all items within the element.
if (form_get_error($element)) {
$element['hour']['#attributes']['class'] = array('error');
$element['minute']['#attributes']['class'] = array('error');
}
$output = '