diff --git a/core/modules/datetime/config/schema/datetime.schema.yml b/core/modules/datetime/config/schema/datetime.schema.yml index b600660..57f70ac 100644 --- a/core/modules/datetime/config/schema/datetime.schema.yml +++ b/core/modules/datetime/config/schema/datetime.schema.yml @@ -89,15 +89,11 @@ field.widget.settings.datetime_default: # Daterange field type. field.storage_settings.daterange: - type: mapping + type: field.storage_settings.datetime label: 'Date range settings' - mapping: - datetime_type: - type: string - label: 'Date type' field.field_settings.daterange: - type: mapping + type: field.field_settings.datetime label: 'Date range settings' field.value.daterange: @@ -117,37 +113,29 @@ field.value.daterange: type: string label: 'Default end date value' -field.formatter.settings.daterange_base: - type: mapping - mapping: - separator: - type: string - label: 'Separator' - timezone_override: - type: string - label: 'Time zone override' - field.formatter.settings.daterange_default: - type: field.formatter.settings.daterange_base + type: field.formatter.settings.datetime_default label: 'Date range default display format settings' mapping: - format_type: + separator: type: string - label: 'Date format' + label: 'Separator' field.formatter.settings.daterange_plain: - type: field.formatter.settings.daterange_base + type: field.formatter.settings.datetime_plain label: 'Date range plain display format settings' + mapping: + separator: + type: string + label: 'Separator' field.formatter.settings.daterange_custom: - type: field.formatter.settings.daterange_base + type: field.formatter.settings.datetime_custom label: 'Date range custom display format settings' mapping: - date_format: + separator: type: string - label: 'Date/time format' - translatable: true - translation context: 'PHP date format' + label: 'Separator' field.widget.settings.daterange_datelist: type: mapping diff --git a/core/modules/datetime/datetime.views.inc b/core/modules/datetime/datetime.views.inc index d82259e..564592b 100644 --- a/core/modules/datetime/datetime.views.inc +++ b/core/modules/datetime/datetime.views.inc @@ -11,6 +11,12 @@ * Implements hook_field_views_data(). */ function datetime_field_views_data(FieldStorageConfigInterface $field_storage) { + // The 'datetime' argument, filter, and sort handlers do not yet work for + // 'daterange' fields, so return an empty array for them, causing + // views_views_data() to fall back to the generic Views integration provided + // by views_field_default_views_data(). + // @todo Fix the handlers and remove this in + // https://www.drupal.org/node/2786577. if ($field_storage->getType() !== 'datetime') { return []; } diff --git a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangeCustomFormatter.php b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangeCustomFormatter.php index aa31a48..4eb9472 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangeCustomFormatter.php +++ b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangeCustomFormatter.php @@ -4,7 +4,6 @@ use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Form\FormStateInterface; -use Drupal\datetime\Plugin\Field\FieldType\DateRangeItem; /** * Plugin implementation of the 'Custom' formatter for 'daterange' fields. @@ -27,7 +26,6 @@ class DateRangeCustomFormatter extends DateTimeCustomFormatter { */ public static function defaultSettings() { return [ - 'date_format' => DATETIME_DATETIME_STORAGE_FORMAT, 'separator' => '-', ] + parent::defaultSettings(); } diff --git a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangeDefaultFormatter.php b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangeDefaultFormatter.php index d798927..57cf008 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangeDefaultFormatter.php +++ b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangeDefaultFormatter.php @@ -4,7 +4,6 @@ use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Form\FormStateInterface; -use Drupal\datetime\Plugin\Field\FieldType\DateRangeItem; /** * Plugin implementation of the 'Default' formatter for 'daterange' fields. @@ -28,7 +27,6 @@ class DateRangeDefaultFormatter extends DateTimeDefaultFormatter { */ public static function defaultSettings() { return [ - 'format_type' => 'medium', 'separator' => '-', ] + parent::defaultSettings(); } diff --git a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangePlainFormatter.php b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangePlainFormatter.php index 622135c..7ba7394 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangePlainFormatter.php +++ b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangePlainFormatter.php @@ -4,7 +4,6 @@ use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Form\FormStateInterface; -use Drupal\datetime\Plugin\Field\FieldType\DateRangeItem; /** * Plugin implementation of the 'Plain' formatter for 'daterange' fields. diff --git a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeCustomFormatter.php b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeCustomFormatter.php index 97141a3..9d96c54 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeCustomFormatter.php +++ b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeCustomFormatter.php @@ -66,7 +66,8 @@ protected function buildDate($date) { $build = [ '#plain_text' => $this->formatDate($date), - ] + $this->defaultCacheContext(); + ]; + $build['#cache']['contexts'][] = 'timezone'; return $build; } diff --git a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeDefaultFormatter.php b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeDefaultFormatter.php index a9b1698..59783aa 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeDefaultFormatter.php +++ b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeDefaultFormatter.php @@ -84,7 +84,8 @@ protected function buildDate($date) { '#attributes' => [ 'datetime' => $iso_date, ], - ] + $this->defaultCacheContext(); + ]; + $build['#cache']['contexts'][] = 'timezone'; return $build; } diff --git a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeFormatterBase.php b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeFormatterBase.php index 024eb40..8d04e44 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeFormatterBase.php +++ b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeFormatterBase.php @@ -140,22 +140,6 @@ public function settingsSummary() { abstract protected function buildDate($date); /** - * Returns the default cache context for the formatter. - * - * @return array - * A render array. - */ - protected function defaultCacheContext() { - return [ - '#cache' => [ - 'contexts' => [ - 'timezone', - ], - ], - ]; - } - - /** * Sets the proper time zone on a DrupalDateTime object for the current user. * * A DrupalDateTime object loaded from the database will have the UTC time diff --git a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimePlainFormatter.php b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimePlainFormatter.php index 1a7bd4d..145b0b0 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimePlainFormatter.php +++ b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimePlainFormatter.php @@ -55,7 +55,8 @@ protected function buildDate($date) { $build = [ '#plain_text' => $this->formatDate($date), - ] + $this->defaultCacheContext(); + ]; + $build['#cache']['contexts'][] = 'timezone'; return $build; } diff --git a/core/modules/datetime/src/Plugin/Field/FieldType/DateRangeFieldItemList.php b/core/modules/datetime/src/Plugin/Field/FieldType/DateRangeFieldItemList.php index f04efb1..3ff6a6c 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldType/DateRangeFieldItemList.php +++ b/core/modules/datetime/src/Plugin/Field/FieldType/DateRangeFieldItemList.php @@ -95,7 +95,8 @@ public static function processDefaultValue($default_value, FieldableEntityInterf // Explicitly call the base class so tht we can get the default value types. $default_value = FieldItemList::processDefaultValue($default_value, $entity, $definition); - // Allow either the start or end date to have a default, but not the other. + // Allow either the start or end date to have a default, but not require + // defaults for both. if (!empty($default_value[0]['default_date_type']) || !empty($default_value[0]['default_end_date_type'])) { // A default value should be in the format and timezone used for date // storage. All-day ranges are stored the same as date+time ranges. We diff --git a/core/modules/datetime/src/Tests/DateRangeFieldTest.php b/core/modules/datetime/src/Tests/DateRangeFieldTest.php index be31cbe..e621653 100644 --- a/core/modules/datetime/src/Tests/DateRangeFieldTest.php +++ b/core/modules/datetime/src/Tests/DateRangeFieldTest.php @@ -15,7 +15,7 @@ use Drupal\simpletest\WebTestBase; /** - * Tests Datetime field functionality. + * Tests Daterange field functionality. * * @group datetime */ @@ -55,12 +55,12 @@ class DateRangeFieldTest extends WebTestBase { protected $field; /** - + * An array of timezone extremes to test. - + * - + * @var string[] - + */ + * An array of timezone extremes to test. + * + * @var string[] + */ protected static $timezones = [ - // UTC-12, no DST. + // UTC-12, no DST. 'Pacific/Kwajalein', // UTC-11, no DST 'Pacific/Midway', @@ -206,7 +206,7 @@ public function testDateRangeField() { datetime_date_default_time($end_date); // Reset display options since these get changed below. - $this->displayOptions =[ + $this->displayOptions = [ 'type' => 'daterange_default', 'label' => 'hidden', 'settings' => [ @@ -546,7 +546,7 @@ public function testDatelistWidget() { // Display creation form. $this->drupalGet('entity_test/add'); - foreach (['value','end-value'] as $column) { + foreach (['value', 'end-value'] as $column) { foreach (['year', 'month', 'day', 'hour', 'minute', 'ampm'] as $element) { $this->assertFieldByXPath("//*[@id=\"edit-$field_name-0-$column-$element\"]", NULL, $element . ' element found.'); $this->assertOptionSelected("edit-$field_name-0-$column-$element", '', 'No ' . $element . ' selected.');