function TimestampItemNormalizer::constructValue

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

Overrides FieldableEntityNormalizerTrait::constructValue

File

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

Class

TimestampItemNormalizer
Converts values for TimestampItem to and from common formats for hal.

Namespace

Drupal\hal\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.