public function BootstrapDatepickerBase::formatDefaultValue in Bootstrap Datepicker 8
Creates a date string 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
object $date: The UTC default date.
string $timezone: The timezone to apply.
string $format: Date format to apply.
Return value
string String for use as a default value in a field widget.
1 call to BootstrapDatepickerBase::formatDefaultValue()
- BootstrapDateWidget::formElement in src/
Plugin/ Field/ FieldWidget/ BootstrapDateWidget.php - Returns the form for a single field widget.
File
- src/
Plugin/ Field/ FieldWidget/ BootstrapDatepickerBase.php, line 713
Class
- BootstrapDatepickerBase
- Base class for SingleDateTime widget types.
Namespace
Drupal\bootstrap_datepicker\Plugin\Field\FieldWidgetCode
public function formatDefaultValue($date, $timezone, $format) {
// 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) {
// A date without time will pick up the current time, use the default
// time.
datetime_date_default_time($date);
}
$date
->setTimezone(new \DateTimeZone($timezone));
// Format date.
return $date
->format($format);
}