You are here

protected function DateRecurDefaultWidget::createDefaultValue in Recurring Dates Field 8

Creates a date object for use as a default value.

This overrides DateRangeWidgetBase to change timezone override.

Parameters

\Drupal\Core\Datetime\DrupalDateTime $date:

string $timezone:

Return value

\Drupal\Core\Datetime\DrupalDateTime

Overrides DateTimeWidgetBase::createDefaultValue

File

src/Plugin/Field/FieldWidget/DateRecurDefaultWidget.php, line 101

Class

DateRecurDefaultWidget
Plugin implementation of the 'date_recur_default_widget' widget.

Namespace

Drupal\date_recur\Plugin\Field\FieldWidget

Code

protected function createDefaultValue($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) {

    // A date without time will pick up the current time, use the default
    // time.
    datetime_date_default_time($date);
  }
  $date
    ->setTimezone(new \DateTimeZone($this
    ->getTimezone()));
  return $date;
}