function date_default_value_part in Date 8
Same name and namespace in other branches
- 7.3 date_elements.inc \date_default_value_part()
- 7.2 date_elements.inc \date_default_value_part()
Helper function for the date default value callback to set either 'value' or 'value2' to its default value.
1 call to date_default_value_part()
- date_default_value in ./
date.module - The callback for setting a default value for an empty date field.
File
- ./
date.module, line 570 - Defines date/time field types.
Code
function date_default_value_part($item, $field, $instance, $langcode, $part = 'value') {
$timezone = date_get_timezone($field['settings']['tz_handling']);
$timezone_db = date_get_timezone_db($field['settings']['tz_handling']);
$date = NULL;
if ($part == 'value') {
$default_value = $instance['settings']['default_value'];
$default_value_code = $instance['settings']['default_value_code'];
}
else {
$default_value = $instance['settings']['default_value2'];
$default_value_code = $instance['settings']['default_value_code2'];
}
if (empty($default_value) || $default_value == 'blank') {
return NULL;
}
elseif ($default_value == 'strtotime' && !empty($default_value_code)) {
$date = new DrupalDateTime($default_value_code, drupal_get_user_timezone());
}
elseif ($part == 'value2' && $default_value == 'same') {
if ($instance['settings']['default_value'] == 'blank' || empty($item[0]['value'])) {
return NULL;
}
else {
// The date stored in 'value' has already been switched to the db timezone.
$date = new DrupalDateTime($item[0]['value'], $timezone_db, DATE_FORMAT_DATETIME);
}
}
elseif ($field['settings']['tz_handling'] == 'none') {
$date = new DrupalDateTime();
}
else {
$date = new DrupalDateTime('now', $timezone);
}
// The default value needs to be in the database timezone.
date_timezone_set($date, timezone_open($timezone_db));
return $date;
}