public function SmartDateNormalizer::denormalize in Smart Date 3.0.x
Same name and namespace in other branches
- 3.1.x src/Normalizer/SmartDateNormalizer.php \Drupal\smart_date\Normalizer\SmartDateNormalizer::denormalize()
- 3.2.x src/Normalizer/SmartDateNormalizer.php \Drupal\smart_date\Normalizer\SmartDateNormalizer::denormalize()
- 3.3.x src/Normalizer/SmartDateNormalizer.php \Drupal\smart_date\Normalizer\SmartDateNormalizer::denormalize()
- 3.4.x src/Normalizer/SmartDateNormalizer.php \Drupal\smart_date\Normalizer\SmartDateNormalizer::denormalize()
Overrides FieldItemNormalizer::denormalize
File
- src/
Normalizer/ SmartDateNormalizer.php, line 25
Class
- SmartDateNormalizer
- Enhances the smart date field so it can be denormalized.
Namespace
Drupal\smart_date\NormalizerCode
public function denormalize($data, $class, $format = NULL, array $context = []) {
$field = parent::denormalize($data, $class, $format, $context);
// Repeat the denormalization of date string for end_value.
$timezone = new DateTimeZone('UTC');
$date = DateTime::createFromFormat($data['format'], $data['end_value'], $timezone);
$field
->get('end_value')
->setValue($date
->getTimestamp());
return $field;
}