StringNormalizer.php

Same filename in this branch
  1. 8.9.x core/modules/jsonapi/tests/modules/jsonapi_test_field_type/src/Normalizer/StringNormalizer.php
Same filename in other branches
  1. 9 core/modules/jsonapi/tests/modules/jsonapi_test_data_type/src/Normalizer/StringNormalizer.php
  2. 9 core/modules/jsonapi/tests/modules/jsonapi_test_field_type/src/Normalizer/StringNormalizer.php
  3. 10 core/modules/jsonapi/tests/modules/jsonapi_test_data_type/src/Normalizer/StringNormalizer.php
  4. 10 core/modules/jsonapi/tests/modules/jsonapi_test_field_type/src/Normalizer/StringNormalizer.php
  5. 11.x core/modules/jsonapi/tests/modules/jsonapi_test_data_type/src/Normalizer/StringNormalizer.php
  6. 11.x core/modules/jsonapi/tests/modules/jsonapi_test_field_type/src/Normalizer/StringNormalizer.php

Namespace

Drupal\jsonapi_test_data_type\Normalizer

File

core/modules/jsonapi/tests/modules/jsonapi_test_data_type/src/Normalizer/StringNormalizer.php

View source
<?php

namespace Drupal\jsonapi_test_data_type\Normalizer;

use Drupal\Core\TypedData\Plugin\DataType\StringData;
use Drupal\serialization\Normalizer\NormalizerBase;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;

/**
 * Normalizes string data weirdly: replaces 'super' with 'NOT' and vice versa.
 */
class StringNormalizer extends NormalizerBase implements DenormalizerInterface {
    
    /**
     * {@inheritdoc}
     */
    protected $supportedInterfaceOrClass = StringData::class;
    
    /**
     * {@inheritdoc}
     */
    public function normalize($object, $format = NULL, array $context = []) {
        return str_replace('super', 'NOT', $object->getValue());
    }
    
    /**
     * {@inheritdoc}
     */
    public function denormalize($data, $class, $format = NULL, array $context = []) {
        return str_replace('NOT', 'super', $data);
    }

}

Classes

Title Deprecated Summary
StringNormalizer Normalizes string data weirdly: replaces 'super' with 'NOT' and vice versa.

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