function TimestampItemNormalizer::constructValue

Same name in this branch
  1. 9 core/modules/serialization/src/Normalizer/TimestampItemNormalizer.php \Drupal\serialization\Normalizer\TimestampItemNormalizer::constructValue()
Same name and namespace in other branches
  1. 8.9.x core/modules/serialization/src/Normalizer/TimestampItemNormalizer.php \Drupal\serialization\Normalizer\TimestampItemNormalizer::constructValue()
  2. 8.9.x 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()

Build the field item value using the incoming data.

Most normalizers that extend this class can simply use this method to construct the denormalized value without having to override denormalize() and re-implementing its validation logic or its call to set the field value.

It's recommended to not override this and instead provide a (de)normalizer at the DataType level.

Parameters

mixed $data: The incoming data for this field item.

array $context: The context passed into the Normalizer.

Return value

mixed The value to use in Entity::setValue().

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.