protected function OpignoDateRangeWidget::createDefaultValue in Opigno calendar 8
Creates a date object for use as a default value.
This will take a default value, apply the proper timezone for display in a widget, and set the default time for date-only fields.
Parameters
\Drupal\Core\Datetime\DrupalDateTime $date: The UTC default date.
string $timezone: The timezone to apply.
Return value
\Drupal\Core\Datetime\DrupalDateTime A date object for use as a default value in a field widget.
File
- src/
Plugin/ Field/ FieldWidget/ OpignoDateRangeWidget.php, line 316
Class
- OpignoDateRangeWidget
- Plugin implementation of the 'opigno_daterange' widget.
Namespace
Drupal\opigno_calendar\Plugin\Field\FieldWidgetCode
protected function createDefaultValue(DrupalDateTime $date, $timezone) {
// The date was created and verified during field_load(), so it is safe to
// use without further inspection.
if ($this
->getFieldSetting('datetime_type') === DateTimeItem::DATETIME_TYPE_DATE) {
$date
->setDefaultDateTime();
}
$date
->setTimezone(new \DateTimeZone($timezone));
return $date;
}