88f24149ca5791b897316994f8497f4450c45895
[yaffs-website] / web / core / modules / serialization / tests / modules / field_normalization_test / src / Normalization / TextItemSillyNormalizer.php
1 <?php
2
3 namespace Drupal\field_normalization_test\Normalization;
4
5 use Drupal\serialization\Normalizer\FieldItemNormalizer;
6 use Drupal\text\Plugin\Field\FieldType\TextItemBase;
7
8 /**
9  * A test TextItem normalizer to test denormalization.
10  */
11 class TextItemSillyNormalizer extends FieldItemNormalizer {
12
13   /**
14    * {@inheritdoc}
15    */
16   protected $supportedInterfaceOrClass = TextItemBase::class;
17
18   /**
19    * {@inheritdoc}
20    */
21   public function normalize($object, $format = NULL, array $context = []) {
22     $data = parent::normalize($object, $format, $context);
23     $data['value'] .= '::silly_suffix';
24     return $data;
25   }
26
27   /**
28    * {@inheritdoc}
29    */
30   protected function constructValue($data, $context) {
31     $value = parent::constructValue($data, $context);
32     $value['value'] = str_replace('::silly_suffix', '', $value['value']);
33     return $value;
34   }
35
36 }