3 namespace Drupal\serialization\Normalizer;
5 use Drupal\Core\Field\Plugin\Field\FieldType\TimestampItem;
6 use Symfony\Component\Serializer\Exception\InvalidArgumentException;
9 * Converts values for TimestampItem to and from common formats.
11 class TimestampItemNormalizer extends FieldItemNormalizer {
13 use TimeStampItemNormalizerTrait;
16 * The interface or class that this Normalizer supports.
20 protected $supportedInterfaceOrClass = TimestampItem::class;
25 public function normalize($field_item, $format = NULL, array $context = []) {
26 $data = parent::normalize($field_item, $format, $context);
28 return $this->processNormalizedValues($data);
34 public function denormalize($data, $class, $format = NULL, array $context = []) {
35 if (empty($data['value'])) {
36 throw new InvalidArgumentException('No "value" attribute present');
39 return parent::denormalize($data, $class, $format, $context);