diff --git a/core/modules/datetime_range/src/Functional/EntityResource/EntityTest/EntityTestAlldayTest.php b/core/modules/datetime_range/src/Functional/EntityResource/EntityTest/EntityTestAlldayTest.php new file mode 100644 index 0000000..645f590 --- /dev/null +++ b/core/modules/datetime_range/src/Functional/EntityResource/EntityTest/EntityTestAlldayTest.php @@ -0,0 +1,21 @@ +getValue()['value']; + $end_value = $item->getValue()['end_value']; + if (!is_string($value)) { + $this->context->addViolation($constraint->badStartType); + } + elseif (!is_string($end_value)) { + $this->context->addViolation($constraint->badEndType); + } + else { + $datetime_type = $item->getFieldDefinition()->getSetting('datetime_type'); + $format = $datetime_type === DateRangeItem::DATETIME_TYPE_DATE ? DateTimeItemInterface::DATE_STORAGE_FORMAT : DateTimeItemInterface::DATETIME_STORAGE_FORMAT; + + $start_date = NULL; + try { + $start_date = DateTimePlus::createFromFormat($format, $value, new \DateTimeZone(DateTimeItemInterface::STORAGE_TIMEZONE)); + } + catch (\InvalidArgumentException $e) { + $this->context->addViolation($constraint->badStartFormat, [ + '@value' => $value, + '@format' => $format, + ]); + return; + } + catch (\UnexpectedValueException $e) { + $this->context->addViolation($constraint->badStartValue, [ + '@value' => $value, + '@format' => $format, + ]); + return; + } + if ($start_date === NULL || $start_date->hasErrors()) { + $this->context->addViolation($constraint->badStartFormat, [ + '@value' => $value, + '@format' => $format, + ]); + } + + $end_date = NULL; + try { + $end_date = DateTimePlus::createFromFormat($format, $end_value, new \DateTimeZone(DateTimeItemInterface::STORAGE_TIMEZONE)); + } + catch (\InvalidArgumentException $e) { + $this->context->addViolation($constraint->badEndFormat, [ + '@end_value' => $end_value, + '@format' => $format, + ]); + return; + } + catch (\UnexpectedValueException $e) { + $this->context->addViolation($constraint->badEndValue, [ + '@end_value' => $end_value, + '@format' => $format, + ]); + return; + } + if ($end_date === NULL || $end_date->hasErrors()) { + $this->context->addViolation($constraint->badEndFormat, [ + '@end_value' => $end_value, + '@format' => $format, + ]); + } + } + } + } + +} diff --git a/core/modules/datetime_range/src/Plugin/Validation/Constraint/DateRangeStartEndConstraint.php b/core/modules/datetime_range/src/Plugin/Validation/Constraint/DateRangeStartEndConstraint.php new file mode 100644 index 0000000..fb46363 --- /dev/null +++ b/core/modules/datetime_range/src/Plugin/Validation/Constraint/DateRangeStartEndConstraint.php @@ -0,0 +1,24 @@ +getValue()['value']; + $end_value = $item->getValue()['end_value']; + + if ($end_value < $value) { + $this->context->addViolation($constraint->badStartEnd, [ + '@value' => $value, + '@end_value' => $end_value, + ]); + } + } + } + +}