diff --git a/core/modules/datetime/datetime.module b/core/modules/datetime/datetime.module index f68bf7e..823de33 100644 --- a/core/modules/datetime/datetime.module +++ b/core/modules/datetime/datetime.module @@ -10,7 +10,7 @@ /** * Defines the timezone that dates should be stored in. * - * @deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use + * @deprecated in Drupal 8.5.x and will be removed before Drupal 9.0.x. Use * \Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface::STORAGE_TIMEZONE * instead. */ @@ -19,7 +19,7 @@ /** * Defines the format that date and time should be stored in. * - * @deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use + * @deprecated in Drupal 8.5.x and will be removed before Drupal 9.0.x. Use * \Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface::DATETIME_STORAGE_FORMAT * instead. */ @@ -28,7 +28,7 @@ /** * Defines the format that dates should be stored in. * - * @deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use + * @deprecated in Drupal 8.5.x and will be removed before Drupal 9.0.x. Use * \Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface::DATE_STORAGE_FORMAT * instead. */ diff --git a/core/modules/datetime/src/Plugin/Validation/Constraint/DateTimeFormatConstraintValidator.php b/core/modules/datetime/src/Plugin/Validation/Constraint/DateTimeFormatConstraintValidator.php index a027a82..4b2ad5d 100644 --- a/core/modules/datetime/src/Plugin/Validation/Constraint/DateTimeFormatConstraintValidator.php +++ b/core/modules/datetime/src/Plugin/Validation/Constraint/DateTimeFormatConstraintValidator.php @@ -4,6 +4,7 @@ use Drupal\Component\Datetime\DateTimePlus; use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem; +use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; @@ -24,10 +25,10 @@ public function validate($item, Constraint $constraint) { } else { $datetime_type = $item->getFieldDefinition()->getSetting('datetime_type'); - $format = $datetime_type === DateTimeItem::DATETIME_TYPE_DATE ? DATETIME_DATE_STORAGE_FORMAT : DATETIME_DATETIME_STORAGE_FORMAT; + $format = $datetime_type === DateTimeItem::DATETIME_TYPE_DATE ? DateTimeItemInterface::DATE_STORAGE_FORMAT : DateTimeItemInterface::DATETIME_STORAGE_FORMAT; $date = NULL; try { - $date = DateTimePlus::createFromFormat($format, $value, new \DateTimeZone(DATETIME_STORAGE_TIMEZONE)); + $date = DateTimePlus::createFromFormat($format, $value, new \DateTimeZone(DateTimeItemInterface::STORAGE_TIMEZONE)); } catch (\InvalidArgumentException $e) { $this->context->addViolation($constraint->badFormat, [ diff --git a/core/modules/datetime/tests/src/Kernel/DateTimeItemTest.php b/core/modules/datetime/tests/src/Kernel/DateTimeItemTest.php index 9884007..fbcedbd 100644 --- a/core/modules/datetime/tests/src/Kernel/DateTimeItemTest.php +++ b/core/modules/datetime/tests/src/Kernel/DateTimeItemTest.php @@ -5,6 +5,7 @@ use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\FieldItemInterface; use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem; +use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface; use Drupal\entity_test\Entity\EntityTest; use Drupal\field\Entity\FieldConfig; use Drupal\Tests\field\Kernel\FieldKernelTestBase; @@ -80,19 +81,19 @@ public function testDateTime() { $this->assertTrue($entity->field_datetime[0] instanceof FieldItemInterface, 'Field item implements interface.'); $this->assertEqual($entity->field_datetime->value, $value); $this->assertEqual($entity->field_datetime[0]->value, $value); - $this->assertEquals(DATETIME_STORAGE_TIMEZONE, $entity->field_datetime->date->getTimeZone()->getName()); + $this->assertEquals(DateTimeItemInterface::STORAGE_TIMEZONE, $entity->field_datetime->date->getTimeZone()->getName()); // Verify changing the date value. $new_value = '2016-11-04T00:21:00'; $entity->field_datetime->value = $new_value; $this->assertEqual($entity->field_datetime->value, $new_value); - $this->assertEquals(DATETIME_STORAGE_TIMEZONE, $entity->field_datetime->date->getTimeZone()->getName()); + $this->assertEquals(DateTimeItemInterface::STORAGE_TIMEZONE, $entity->field_datetime->date->getTimeZone()->getName()); // Read changed entity and assert changed values. $this->entityValidateAndSave($entity); $entity = EntityTest::load($id); $this->assertEqual($entity->field_datetime->value, $new_value); - $this->assertEquals(DATETIME_STORAGE_TIMEZONE, $entity->field_datetime->date->getTimeZone()->getName()); + $this->assertEquals(DateTimeItemInterface::STORAGE_TIMEZONE, $entity->field_datetime->date->getTimeZone()->getName()); // Test the generateSampleValue() method. $entity = EntityTest::create(); @@ -121,19 +122,19 @@ public function testDateOnly() { $this->assertTrue($entity->field_datetime[0] instanceof FieldItemInterface, 'Field item implements interface.'); $this->assertEqual($entity->field_datetime->value, $value); $this->assertEqual($entity->field_datetime[0]->value, $value); - $this->assertEquals(DATETIME_STORAGE_TIMEZONE, $entity->field_datetime->date->getTimeZone()->getName()); + $this->assertEquals(DateTimeItemInterface::STORAGE_TIMEZONE, $entity->field_datetime->date->getTimeZone()->getName()); // Verify changing the date value. $new_value = '2016-11-04'; $entity->field_datetime->value = $new_value; $this->assertEqual($entity->field_datetime->value, $new_value); - $this->assertEquals(DATETIME_STORAGE_TIMEZONE, $entity->field_datetime->date->getTimeZone()->getName()); + $this->assertEquals(DateTimeItemInterface::STORAGE_TIMEZONE, $entity->field_datetime->date->getTimeZone()->getName()); // Read changed entity and assert changed values. $this->entityValidateAndSave($entity); $entity = EntityTest::load($id); $this->assertEqual($entity->field_datetime->value, $new_value); - $this->assertEquals(DATETIME_STORAGE_TIMEZONE, $entity->field_datetime->date->getTimeZone()->getName()); + $this->assertEquals(DateTimeItemInterface::STORAGE_TIMEZONE, $entity->field_datetime->date->getTimeZone()->getName()); // Test the generateSampleValue() method. $entity = EntityTest::create(); @@ -158,7 +159,7 @@ public function testSetValue() { $id = $entity->id(); $entity = EntityTest::load($id); $this->assertEqual($entity->field_datetime[0]->value, $value, 'DateTimeItem::setValue() works with string value.'); - $this->assertEquals(DATETIME_STORAGE_TIMEZONE, $entity->field_datetime->date->getTimeZone()->getName()); + $this->assertEquals(DateTimeItemInterface::STORAGE_TIMEZONE, $entity->field_datetime->date->getTimeZone()->getName()); // Test DateTimeItem::setValue() using property array. $entity = EntityTest::create(); @@ -169,7 +170,7 @@ public function testSetValue() { $id = $entity->id(); $entity = EntityTest::load($id); $this->assertEqual($entity->field_datetime[0]->value, $value, 'DateTimeItem::setValue() works with array value.'); - $this->assertEquals(DATETIME_STORAGE_TIMEZONE, $entity->field_datetime->date->getTimeZone()->getName()); + $this->assertEquals(DateTimeItemInterface::STORAGE_TIMEZONE, $entity->field_datetime->date->getTimeZone()->getName()); // Test a date-only field. $this->fieldStorage->setSetting('datetime_type', DateTimeItem::DATETIME_TYPE_DATE); @@ -184,7 +185,7 @@ public function testSetValue() { $id = $entity->id(); $entity = EntityTest::load($id); $this->assertEqual($entity->field_datetime[0]->value, $value, 'DateTimeItem::setValue() works with string value.'); - $this->assertEquals(DATETIME_STORAGE_TIMEZONE, $entity->field_datetime->date->getTimeZone()->getName()); + $this->assertEquals(DateTimeItemInterface::STORAGE_TIMEZONE, $entity->field_datetime->date->getTimeZone()->getName()); // Test DateTimeItem::setValue() using property array. $entity = EntityTest::create(); @@ -195,7 +196,7 @@ public function testSetValue() { $id = $entity->id(); $entity = EntityTest::load($id); $this->assertEqual($entity->field_datetime[0]->value, $value, 'DateTimeItem::setValue() works with array value.'); - $this->assertEquals(DATETIME_STORAGE_TIMEZONE, $entity->field_datetime->date->getTimeZone()->getName()); + $this->assertEquals(DateTimeItemInterface::STORAGE_TIMEZONE, $entity->field_datetime->date->getTimeZone()->getName()); } /** @@ -215,7 +216,7 @@ public function testSetValueProperty() { $id = $entity->id(); $entity = EntityTest::load($id); $this->assertEqual($entity->field_datetime[0]->value, $value, '"Value" property can be set directly.'); - $this->assertEquals(DATETIME_STORAGE_TIMEZONE, $entity->field_datetime->date->getTimeZone()->getName()); + $this->assertEquals(DateTimeItemInterface::STORAGE_TIMEZONE, $entity->field_datetime->date->getTimeZone()->getName()); // Test Date::setValue() with a date-only field. // Test a date+time field. @@ -230,7 +231,7 @@ public function testSetValueProperty() { $id = $entity->id(); $entity = EntityTest::load($id); $this->assertEqual($entity->field_datetime[0]->value, $value, '"Value" property can be set directly.'); - $this->assertEquals(DATETIME_STORAGE_TIMEZONE, $entity->field_datetime->date->getTimeZone()->getName()); + $this->assertEquals(DateTimeItemInterface::STORAGE_TIMEZONE, $entity->field_datetime->date->getTimeZone()->getName()); } /**