You are here

protected function DateRecurBasicWidget::createDefaultValue in Recurring Dates Field 3.x

Same name and namespace in other branches
  1. 8.2 src/Plugin/Field/FieldWidget/DateRecurBasicWidget.php \Drupal\date_recur\Plugin\Field\FieldWidget\DateRecurBasicWidget::createDefaultValue()
  2. 3.0.x src/Plugin/Field/FieldWidget/DateRecurBasicWidget.php \Drupal\date_recur\Plugin\Field\FieldWidget\DateRecurBasicWidget::createDefaultValue()
  3. 3.1.x src/Plugin/Field/FieldWidget/DateRecurBasicWidget.php \Drupal\date_recur\Plugin\Field\FieldWidget\DateRecurBasicWidget::createDefaultValue()

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.

Overrides DateTimeWidgetBase::createDefaultValue

1 call to DateRecurBasicWidget::createDefaultValue()
DateRecurBasicWidget::createDateRecurDefaultValue in src/Plugin/Field/FieldWidget/DateRecurBasicWidget.php
Set element default value and time zone.

File

src/Plugin/Field/FieldWidget/DateRecurBasicWidget.php, line 227

Class

DateRecurBasicWidget
Basic RRULE widget.

Namespace

Drupal\date_recur\Plugin\Field\FieldWidget

Code

protected function createDefaultValue($date, $timezone) : DrupalDateTime {
  assert($date instanceof DrupalDateTime);
  assert(is_string($timezone));

  // Cannot set time zone here as field item contains time zone.
  if ($this
    ->getFieldSetting('datetime_type') == DateTimeItem::DATETIME_TYPE_DATE) {
    $date
      ->setDefaultDateTime();
  }
  return $date;
}