Skip to content
Snippets Groups Projects

fix: better handling for the date format descriptions

Open Dylan Fontaine requested to merge issue/date-1244458:1244458-reroll into 7.x-2.x
3 files
+ 96
54
Compare changes
  • Side-by-side
  • Inline
Files
3
+ 18
20
@@ -206,7 +206,7 @@ function date_popup_element_info() {
// - changeYear => TRUE
// - autoPopUp => 'focus'
// - closeAtTop => FALSE
// - speed => 'immediate'
// - speed => 'immediate'.
$type['date_popup'] = array(
'#input' => TRUE,
'#tree' => TRUE,
@@ -321,6 +321,12 @@ function date_popup_element_process($element, &$form_state, $form) {
);
}
// Display date element description setting.
if (isset($element['#instance'])) {
$element['#show_element_description'] = $element['#instance']['settings']['show_element_description'] ?? FALSE;
}
$element['#show_element_description'] = $element['#show_element_description'] ?? FALSE;
$element['date'] = date_popup_process_date_part($element);
$element['time'] = date_popup_process_time_part($element);
@@ -441,15 +447,11 @@ function date_popup_process_date_part(&$element) {
'#ajax' => !empty($element['#ajax']) ? $element['#ajax'] : FALSE,
'#required' => $element['#required'],
);
// Do NOT overwrite the actual input with the default value.
// @todo Figure out exactly when this is needed, in many places it is not.
$sub_element['#description'] = ' ' . t('E.g., @date', array(
'@date' => date_format_date(
date_example_date(),
'custom',
date_popup_date_format($element)
),
));
// Display date element description as placeholder.
if (!empty($element['#show_element_description'])) {
$sub_element['#attributes']['placeholder'] = date_format_date(date_example_date(), 'custom', date_popup_date_format($element));
}
return $sub_element;
}
@@ -507,7 +509,7 @@ function date_popup_process_time_part(&$element) {
$grans = array('hour', 'minute', 'second');
$time_granularity = array_intersect($granularity, $grans);
$format = date_popup_format_to_popup_time(date_limit_format($element['#date_format'], $time_granularity), 'wvega');
$default_value = isset($element['#default_value']) ? $element['#default_value'] : '';
$default_value = $element['#default_value'] ?? '';
// The first value in the dropdown list should be the same as the element
// default_value, but it needs to be in JS format (i.e. milliseconds since
// the epoch).
@@ -551,17 +553,13 @@ function date_popup_process_time_part(&$element) {
'#required' => $element['#required'],
);
// Do NOT overwrite the actual input with the default value.
// @todo Figure out exactly when this is needed, in many places it is not.
$example_date = date_now();
date_increment_round($example_date, $element['#date_increment']);
$sub_element['#description'] = t('E.g., @date', array(
'@date' => date_format_date(
$example_date,
'custom',
date_popup_time_format($element)
),
));
// Display date element description as placeholder.
if (!empty($element['#show_element_description'])) {
$sub_element['#attributes']['placeholder'] = date_format_date(date_example_date(), 'custom', date_popup_time_format($element));
}
return ($sub_element);
}
Loading