Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / datetime_range / src / Plugin / Field / FieldWidget / DateRangeWidgetBase.php
index e99374c20f17b5e63b3b3b78be02fa4724db76a8..85fda9ba536dddb99fde72445ad2f13fbfa59cda 100644 (file)
@@ -5,7 +5,7 @@ namespace Drupal\datetime_range\Plugin\Field\FieldWidget;
 use Drupal\Core\Datetime\DrupalDateTime;
 use Drupal\Core\Field\FieldItemListInterface;
 use Drupal\Core\Form\FormStateInterface;
-use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem;
+use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface;
 use Drupal\datetime\Plugin\Field\FieldWidget\DateTimeWidgetBase;
 use Drupal\datetime_range\Plugin\Field\FieldType\DateRangeItem;
 
@@ -58,10 +58,7 @@ class DateRangeWidgetBase extends DateTimeWidgetBase {
         $start_date = $item['value'];
         switch ($this->getFieldSetting('datetime_type')) {
           case DateRangeItem::DATETIME_TYPE_DATE:
-            // If this is a date-only field, set it to the default time so the
-            // timezone conversion can be reversed.
-            datetime_date_default_time($start_date);
-            $format = DATETIME_DATE_STORAGE_FORMAT;
+            $format = DateTimeItemInterface::DATE_STORAGE_FORMAT;
             break;
 
           case DateRangeItem::DATETIME_TYPE_ALLDAY:
@@ -71,15 +68,15 @@ class DateRangeWidgetBase extends DateTimeWidgetBase {
             // we need to explicitly set the timezone.
             $start_date->setTimeZone(timezone_open(drupal_get_user_timezone()));
             $start_date->setTime(0, 0, 0);
-            $format = DATETIME_DATETIME_STORAGE_FORMAT;
+            $format = DateTimeItemInterface::DATETIME_STORAGE_FORMAT;
             break;
 
           default:
-            $format = DATETIME_DATETIME_STORAGE_FORMAT;
+            $format = DateTimeItemInterface::DATETIME_STORAGE_FORMAT;
             break;
         }
         // Adjust the date for storage.
-        $start_date->setTimezone(new \DateTimezone(DATETIME_STORAGE_TIMEZONE));
+        $start_date->setTimezone(new \DateTimezone(DateTimeItemInterface::STORAGE_TIMEZONE));
         $item['value'] = $start_date->format($format);
       }
 
@@ -88,10 +85,7 @@ class DateRangeWidgetBase extends DateTimeWidgetBase {
         $end_date = $item['end_value'];
         switch ($this->getFieldSetting('datetime_type')) {
           case DateRangeItem::DATETIME_TYPE_DATE:
-            // If this is a date-only field, set it to the default time so the
-            // timezone conversion can be reversed.
-            datetime_date_default_time($end_date);
-            $format = DATETIME_DATE_STORAGE_FORMAT;
+            $format = DateTimeItemInterface::DATE_STORAGE_FORMAT;
             break;
 
           case DateRangeItem::DATETIME_TYPE_ALLDAY:
@@ -101,15 +95,15 @@ class DateRangeWidgetBase extends DateTimeWidgetBase {
             // we need to explicitly set the timezone.
             $end_date->setTimeZone(timezone_open(drupal_get_user_timezone()));
             $end_date->setTime(23, 59, 59);
-            $format = DATETIME_DATETIME_STORAGE_FORMAT;
+            $format = DateTimeItemInterface::DATETIME_STORAGE_FORMAT;
             break;
 
           default:
-            $format = DATETIME_DATETIME_STORAGE_FORMAT;
+            $format = DateTimeItemInterface::DATETIME_STORAGE_FORMAT;
             break;
         }
         // Adjust the date for storage.
-        $end_date->setTimezone(new \DateTimezone(DATETIME_STORAGE_TIMEZONE));
+        $end_date->setTimezone(new \DateTimezone(DateTimeItemInterface::STORAGE_TIMEZONE));
         $item['end_value'] = $end_date->format($format);
       }
     }
@@ -142,30 +136,4 @@ class DateRangeWidgetBase extends DateTimeWidgetBase {
     }
   }
 
-  /**
-   * 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.
-   *
-   * @param \Drupal\Core\Datetime\DrupalDateTime $date
-   *   The UTC default date.
-   * @param string $timezone
-   *   The timezone to apply.
-   *
-   * @return \Drupal\Core\Datetime\DrupalDateTime
-   *   A date object for use as a default value in a field widget.
-   */
-  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($timezone));
-    return $date;
-  }
-
 }