function DateTimeFieldItemList::processDefaultValue
Same name in other branches
- 8.9.x core/modules/datetime/src/Plugin/Field/FieldType/DateTimeFieldItemList.php \Drupal\datetime\Plugin\Field\FieldType\DateTimeFieldItemList::processDefaultValue()
- 10 core/modules/datetime/src/Plugin/Field/FieldType/DateTimeFieldItemList.php \Drupal\datetime\Plugin\Field\FieldType\DateTimeFieldItemList::processDefaultValue()
- 11.x core/modules/datetime/src/Plugin/Field/FieldType/DateTimeFieldItemList.php \Drupal\datetime\Plugin\Field\FieldType\DateTimeFieldItemList::processDefaultValue()
Overrides FieldItemList::processDefaultValue
1 method overrides DateTimeFieldItemList::processDefaultValue()
- DateRangeFieldItemList::processDefaultValue in core/
modules/ datetime_range/ src/ Plugin/ Field/ FieldType/ DateRangeFieldItemList.php - Processes the default value before being applied.
File
-
core/
modules/ datetime/ src/ Plugin/ Field/ FieldType/ DateTimeFieldItemList.php, line 91
Class
- DateTimeFieldItemList
- Represents a configurable entity datetime field.
Namespace
Drupal\datetime\Plugin\Field\FieldTypeCode
public static function processDefaultValue($default_value, FieldableEntityInterface $entity, FieldDefinitionInterface $definition) {
$default_value = parent::processDefaultValue($default_value, $entity, $definition);
if (isset($default_value[0]['default_date_type'])) {
if ($definition->getSetting('datetime_type') === DateTimeItem::DATETIME_TYPE_DATE) {
// A default date only value should be in the format used for date
// storage but in the user's local timezone.
$date = new DrupalDateTime($default_value[0]['default_date'], date_default_timezone_get());
$format = DateTimeItemInterface::DATE_STORAGE_FORMAT;
}
else {
// A default date+time value should be in the format and timezone used
// for date storage.
$date = new DrupalDateTime($default_value[0]['default_date'], DateTimeItemInterface::STORAGE_TIMEZONE);
$format = DateTimeItemInterface::DATETIME_STORAGE_FORMAT;
}
$value = $date->format($format);
// We only provide a default value for the first item, as do all fields.
// Otherwise, there is no way to clear out unwanted values on multiple value
// fields.
$default_value = [
[
'value' => $value,
'date' => $date,
],
];
}
return $default_value;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.