You are here

protected function DateRecurBasicWidget::createDateRecurDefaultValue in Recurring Dates Field 8.2

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

Set element default value and time zone.

Parameters

array $element: The element.

\Drupal\date_recur\Plugin\Field\FieldType\DateRecurItem $item: The date recur field item.

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

File

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

Class

DateRecurBasicWidget
Basic RRULE widget.

Namespace

Drupal\date_recur\Plugin\Field\FieldWidget

Code

protected function createDateRecurDefaultValue(array &$element, DateRecurItem $item) : void {
  $startDate = $item->start_date;
  $startDateEnd = $item->end_date;
  $timeZone = isset($item->timezone) ? new \DateTimeZone($item->timezone) : NULL;
  if ($timeZone) {
    $element['value']['#date_timezone'] = $element['end_value']['#date_timezone'] = $timeZone
      ->getName();
    if ($startDate) {
      $startDate
        ->setTimezone($timeZone);
      $element['value']['#default_value'] = $this
        ->createDefaultValue($startDate, $timeZone
        ->getName());
    }
    if ($startDateEnd) {
      $startDateEnd
        ->setTimezone($timeZone);
      $element['end_value']['#default_value'] = $this
        ->createDefaultValue($startDateEnd, $timeZone
        ->getName());
    }
  }
}