You are here

public function SmartDateNormalizer::denormalize in Smart Date 3.2.x

Same name and namespace in other branches
  1. 3.0.x src/Normalizer/SmartDateNormalizer.php \Drupal\smart_date\Normalizer\SmartDateNormalizer::denormalize()
  2. 3.1.x src/Normalizer/SmartDateNormalizer.php \Drupal\smart_date\Normalizer\SmartDateNormalizer::denormalize()
  3. 3.3.x src/Normalizer/SmartDateNormalizer.php \Drupal\smart_date\Normalizer\SmartDateNormalizer::denormalize()
  4. 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\Normalizer

Code

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;
}