class TimestampItemNormalizer
Same name in this branch
- 9 core/modules/serialization/src/Normalizer/TimestampItemNormalizer.php \Drupal\serialization\Normalizer\TimestampItemNormalizer
Same name and namespace in other branches
- 8.9.x core/modules/serialization/src/Normalizer/TimestampItemNormalizer.php \Drupal\serialization\Normalizer\TimestampItemNormalizer
- 8.9.x core/modules/hal/src/Normalizer/TimestampItemNormalizer.php \Drupal\hal\Normalizer\TimestampItemNormalizer
- 10 core/modules/serialization/src/Normalizer/TimestampItemNormalizer.php \Drupal\serialization\Normalizer\TimestampItemNormalizer
- 11.x core/modules/serialization/src/Normalizer/TimestampItemNormalizer.php \Drupal\serialization\Normalizer\TimestampItemNormalizer
Converts values for TimestampItem to and from common formats for hal.
Overrides FieldItemNormalizer to
- during normalization, add the 'format' key to assist consumers
- during denormalization, use \Drupal\serialization\Normalizer\TimestampNormalizer
Hierarchy
- class \Drupal\serialization\Normalizer\NormalizerBase extends \Symfony\Component\Serializer\SerializerAwareInterface, \Drupal\serialization\Normalizer\CacheableNormalizerInterface, \Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface uses \Symfony\Component\Serializer\SerializerAwareTrait
- class \Drupal\hal\Normalizer\NormalizerBase extends \Symfony\Component\Serializer\Normalizer\DenormalizerInterface implements \Drupal\serialization\Normalizer\NormalizerBase
- class \Drupal\hal\Normalizer\FieldItemNormalizer uses \Drupal\serialization\Normalizer\FieldableEntityNormalizerTrait, \Drupal\serialization\Normalizer\SerializedColumnNormalizerTrait implements \Drupal\hal\Normalizer\NormalizerBase
- class \Drupal\hal\Normalizer\TimestampItemNormalizer implements \Drupal\hal\Normalizer\FieldItemNormalizer
- class \Drupal\hal\Normalizer\FieldItemNormalizer uses \Drupal\serialization\Normalizer\FieldableEntityNormalizerTrait, \Drupal\serialization\Normalizer\SerializedColumnNormalizerTrait implements \Drupal\hal\Normalizer\NormalizerBase
- class \Drupal\hal\Normalizer\NormalizerBase extends \Symfony\Component\Serializer\Normalizer\DenormalizerInterface implements \Drupal\serialization\Normalizer\NormalizerBase
Expanded class hierarchy of TimestampItemNormalizer
1 string reference to 'TimestampItemNormalizer'
- hal.services.yml in core/
modules/ hal/ hal.services.yml - core/modules/hal/hal.services.yml
1 service uses TimestampItemNormalizer
File
-
core/
modules/ hal/ src/ Normalizer/ TimestampItemNormalizer.php, line 17
Namespace
Drupal\hal\NormalizerView source
class TimestampItemNormalizer extends FieldItemNormalizer {
/**
* {@inheritdoc}
*/
protected $supportedInterfaceOrClass = TimestampItem::class;
/**
* {@inheritdoc}
*/
protected function normalizedFieldValues(FieldItemInterface $field_item, $format, array $context) {
return parent::normalizedFieldValues($field_item, $format, $context) + [
// 'format' is not a property on Timestamp objects. This is present to
// assist consumers of this data.
'format' => \DateTime::RFC3339,
];
}
/**
* {@inheritdoc}
*/
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),
];
}
/**
* {@inheritdoc}
*/
public function hasCacheableSupportsMethod() : bool {
return TRUE;
}
}
Members
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.