function DateRangeItem::generateSampleValue
Same name in other branches
- 8.9.x core/modules/datetime_range/src/Plugin/Field/FieldType/DateRangeItem.php \Drupal\datetime_range\Plugin\Field\FieldType\DateRangeItem::generateSampleValue()
- 10 core/modules/datetime_range/src/Plugin/Field/FieldType/DateRangeItem.php \Drupal\datetime_range\Plugin\Field\FieldType\DateRangeItem::generateSampleValue()
- 11.x core/modules/datetime_range/src/Plugin/Field/FieldType/DateRangeItem.php \Drupal\datetime_range\Plugin\Field\FieldType\DateRangeItem::generateSampleValue()
Overrides DateTimeItem::generateSampleValue
File
-
core/
modules/ datetime_range/ src/ Plugin/ Field/ FieldType/ DateRangeItem.php, line 92
Class
- DateRangeItem
- Plugin implementation of the 'daterange' field type.
Namespace
Drupal\datetime_range\Plugin\Field\FieldTypeCode
public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
$type = $field_definition->getSetting('datetime_type');
// Just pick a date in the past year. No guidance is provided by this Field
// type.
$start = REQUEST_TIME - mt_rand(0, 86400 * 365) - 86400;
$end = $start + 86400;
if ($type == static::DATETIME_TYPE_DATETIME) {
$values['value'] = gmdate(DateTimeItemInterface::DATETIME_STORAGE_FORMAT, $start);
$values['end_value'] = gmdate(DateTimeItemInterface::DATETIME_STORAGE_FORMAT, $end);
}
else {
$values['value'] = gmdate(DateTimeItemInterface::DATE_STORAGE_FORMAT, $start);
$values['end_value'] = gmdate(DateTimeItemInterface::DATE_STORAGE_FORMAT, $end);
}
return $values;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.