TextItemSillyNormalizer.php

Same filename in other branches
  1. 9 core/modules/serialization/tests/modules/field_normalization_test/src/Normalization/TextItemSillyNormalizer.php
  2. 8.9.x core/modules/serialization/tests/modules/field_normalization_test/src/Normalization/TextItemSillyNormalizer.php
  3. 11.x core/modules/serialization/tests/modules/field_normalization_test/src/Normalization/TextItemSillyNormalizer.php

Namespace

Drupal\field_normalization_test\Normalization

File

core/modules/serialization/tests/modules/field_normalization_test/src/Normalization/TextItemSillyNormalizer.php

View source
<?php

namespace Drupal\field_normalization_test\Normalization;

use Drupal\serialization\Normalizer\FieldItemNormalizer;
use Drupal\text\Plugin\Field\FieldType\TextItemBase;

/**
 * A test TextItem normalizer to test denormalization.
 */
class TextItemSillyNormalizer extends FieldItemNormalizer {
    
    /**
     * {@inheritdoc}
     */
    public function normalize($object, $format = NULL, array $context = []) : array|string|int|float|bool|\ArrayObject|null {
        $data = parent::normalize($object, $format, $context);
        $data['value'] .= '::silly_suffix';
        return $data;
    }
    
    /**
     * {@inheritdoc}
     */
    protected function constructValue($data, $context) {
        $value = parent::constructValue($data, $context);
        $value['value'] = str_replace('::silly_suffix', '', $value['value']);
        return $value;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getSupportedTypes(?string $format) : array {
        return [
            TextItemBase::class => TRUE,
        ];
    }

}

Classes

Title Deprecated Summary
TextItemSillyNormalizer A test TextItem normalizer to test denormalization.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.