getValue()['value']; if (!is_string($value)) { $this->context->addViolation($constraint->badType); } else { $datetime_type = $item->getFieldDefinition()->getSetting('datetime_type'); $format = $datetime_type === DateTimeItem::DATETIME_TYPE_DATE ? DATETIME_DATE_STORAGE_FORMAT : DATETIME_DATETIME_STORAGE_FORMAT; $date = NULL; try { $date = DateTimePlus::createFromFormat($format, $value, new \DateTimeZone(DATETIME_STORAGE_TIMEZONE)); } catch (\InvalidArgumentException $e) { $this->context->addViolation($constraint->badFormat, [ '@value' => $value, '@format' => $format, ]); return; } catch (\UnexpectedValueException $e) { $this->context->addViolation($constraint->badValue, [ '@value' => $value, '@format' => $format, ]); return; } if ($date === NULL || $date->hasErrors()) { $this->context->addViolation($constraint->badFormat, [ '@value' => $value, '@format' => $format, ]); } } } } }