1 date.elements.inc | _date_popup_process_time_part(&$element) |
Process the time portion of the element.
File
- core/
modules/ date/ date.elements.inc, line 1128 - Date forms and form themes and validation.
Code
function _date_popup_process_time_part(&$element) {
$granularity = date_format_order($element['#date_format']);
$has_time = date_has_time($granularity);
if (empty($has_time)) {
return array();
}
// When used as a Views exposed filter widget, $element['#value'] contains an
// array instead an string. Fill the 'time' string in this case.
$mock = NULL;
$callback_values = date_popup_element_value_callback($element, FALSE, $mock);
if (!isset($element['#value']['time']) && isset($callback_values['time'])) {
$element['#value']['time'] = $callback_values['time'];
}
// Manually build this element and set the value -
// this will prevent corrupting the parent value.
$parents = array_merge($element['#parents'], array('time'));
$sub_element = array(
'#type' => 'textfield',
'#title' => isset($element['#title']) ? t('Time for @label', array('@label' => $element['#title'])) : t('Time'),
'#title_display' => 'invisible',
'#default_value' => $element['#value']['time'],
'#size' => 15,
'#maxlength' => 10,
'#parents' => $parents,
'#name' => array_shift($parents) . '[' . implode('][', $parents) . ']',
'#ajax' => !empty($element['#ajax']) ? $element['#ajax'] : FALSE,
'#attached' => array('library' => array(
array('system', 'jquery.timeentry')
)),
'#attributes' => $element['#attributes'],
);
$sub_element['#value'] = $sub_element['#default_value'];
// Add a placeholder sample text to the time field.
if (!isset($sub_element['#attributes']['placeholder'])) {
$example_date = date_now();
date_increment_round($example_date, $element['#date_increment']);
$sub_element['#attributes']['placeholder'] = t('e.g. @date', array(
'@date' => date_format_date(
$example_date,
'custom',
_date_popup_time_format($element)
)));
}
// Add in the timepicker if set.
if ($element['#timepicker']) {
$settings = array(
'show24Hours' => (strpos($element['#date_format'], 'H') !== FALSE || strpos($element['#date_format'], 'G') !== FALSE) ? TRUE : FALSE,
'showSeconds' => (in_array('second', $granularity) ? TRUE : FALSE),
'timeSteps' => array(1, intval($element['#date_increment']), (in_array('second', $granularity) ? $element['#date_increment'] : 0)),
'fromTo' => isset($fromto),
'spinnerImage' => '',
);
// Determine if we are using lowercase or uppercase am/pm and translate.
if (strpos($element['#date_format'], 'a') !== FALSE) {
$settings['ampmNames'] = array(t('am'), t('pm'));
}
else {
$settings['ampmNames'] = array(t('AM'), t('PM'));
}
// Determine if we should have a leading space before the am/pm.
if (strpos($element['#date_format'], ' A') !== FALSE || strpos($element['#date_format'], ' a') !== FALSE) {
$settings['ampmPrefix'] = ' ';
}
$sub_element['#attributes'] += array('data-timeentry' => json_encode($settings));
}
return ($sub_element);
}