function TimestampItemNormalizer::constructValue

Same name in this branch
  1. 9 core/modules/hal/src/Normalizer/TimestampItemNormalizer.php \Drupal\hal\Normalizer\TimestampItemNormalizer::constructValue()
Same name and namespace in other branches
  1. 11.x core/modules/serialization/src/Normalizer/TimestampItemNormalizer.php \Drupal\serialization\Normalizer\TimestampItemNormalizer::constructValue()
  2. 10 core/modules/serialization/src/Normalizer/TimestampItemNormalizer.php \Drupal\serialization\Normalizer\TimestampItemNormalizer::constructValue()
  3. 8.9.x core/modules/serialization/src/Normalizer/TimestampItemNormalizer.php \Drupal\serialization\Normalizer\TimestampItemNormalizer::constructValue()
  4. 8.9.x core/modules/hal/src/Normalizer/TimestampItemNormalizer.php \Drupal\hal\Normalizer\TimestampItemNormalizer::constructValue()

File

core/modules/serialization/src/Normalizer/TimestampItemNormalizer.php, line 38

Class

TimestampItemNormalizer
Converts values for TimestampItem to and from common formats.

Namespace

Drupal\serialization\Normalizer

Code

protected function constructValue($data, $context) {
  if (!empty($data['format'])) {
    $context['datetime_allowed_formats'] = [
      $data['format'],
    ];
  }
  return [
    'value' => $this->serializer
      ->denormalize($data['value'], Timestamp::class, NULL, $context),
  ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.