You are here

protected function DateTimeDayWidgetBase::createDateTimeDayDefaultValue in Date time day 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.

1 call to DateTimeDayWidgetBase::createDateTimeDayDefaultValue()
DateTimeDayWidgetBase::formElement in src/Plugin/Field/FieldWidget/DateTimeDayWidgetBase.php
Returns the form for a single field widget.

File

src/Plugin/Field/FieldWidget/DateTimeDayWidgetBase.php, line 134

Class

DateTimeDayWidgetBase
Base class for the 'datetimeday_*' widgets.

Namespace

Drupal\date_time_day\Plugin\Field\FieldWidget

Code

protected function createDateTimeDayDefaultValue(DrupalDateTime $date, $timezone) {
  $date
    ->setTimezone(new \DateTimeZone($timezone));
  return $date;
}