1 date.elements.inc | date_default_value($field, $instance, $langcode) |
The callback for setting a default value for an empty date field.
File
- core/
modules/ date/ date.elements.inc, line 856 - Date forms and form themes and validation.
Code
function date_default_value($field, $instance, $langcode) {
$item = array();
$db_format = date_type_format($field['type']);
$date = date_default_value_part($item, $field, $instance, $langcode, 'value');
if (is_object($date) && empty($date->errors)) {
$item[0]['value'] = date_format($date, $db_format);
}
else {
$item[0]['value'] = '';
}
if (!empty($field['settings']['todate'])) {
$date2 = date_default_value_part($item, $field, $instance, $langcode, 'value2');
if (is_object($date2) && empty($date2->errors)) {
$item[0]['value2'] = date_format($date2, $db_format);
}
else {
$item[0]['value2'] = '';
}
}
// Make sure the default value has the same construct as a loaded field value
// to avoid errors if the default value is used on a hidden element.
$item[0]['timezone'] = date_get_timezone($field['settings']['tz_handling']);
$item[0]['timezone_db'] = date_get_timezone_db($field['settings']['tz_handling']);
$item[0]['date_type'] = $field['type'];
if (!isset($item[0]['value2'])) {
$item[0]['value2'] = $item[0]['value'];
}
return $item;
}