1<?php 2 3namespace Drupal\test_datatype_boolean_emoji_normalizer\Normalizer; 4 5use Drupal\Core\TypedData\Plugin\DataType\BooleanData; 6use Drupal\serialization\Normalizer\NormalizerBase; 7use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; 8 9/** 10 * Normalizes boolean data weirdly: renders them as (TRUE) or (FALSE). 11 */ 12class BooleanNormalizer extends NormalizerBase implements DenormalizerInterface { 13 14 /** 15 * {@inheritdoc} 16 */ 17 protected $supportedInterfaceOrClass = BooleanData::class; 18 19 /** 20 * {@inheritdoc} 21 */ 22 public function normalize($object, $format = NULL, array $context = []) { 23 return $object->getValue() ? '' : ''; 24 } 25 26 /** 27 * {@inheritdoc} 28 */ 29 public function denormalize($data, $class, $format = NULL, array $context = []) { 30 if (!in_array($data, ['', ''], TRUE)) { 31 throw new \UnexpectedValueException('Only and are acceptable values.'); 32 } 33 return $data === ''; 34 } 35 36} 37