StringNormalizer.php
Same filename in this branch
Same filename in other branches
- 9 core/modules/jsonapi/tests/modules/jsonapi_test_data_type/src/Normalizer/StringNormalizer.php
- 9 core/modules/jsonapi/tests/modules/jsonapi_test_field_type/src/Normalizer/StringNormalizer.php
- 8.9.x core/modules/jsonapi/tests/modules/jsonapi_test_data_type/src/Normalizer/StringNormalizer.php
- 8.9.x core/modules/jsonapi/tests/modules/jsonapi_test_field_type/src/Normalizer/StringNormalizer.php
- 10 core/modules/jsonapi/tests/modules/jsonapi_test_data_type/src/Normalizer/StringNormalizer.php
- 10 core/modules/jsonapi/tests/modules/jsonapi_test_field_type/src/Normalizer/StringNormalizer.php
Namespace
Drupal\jsonapi_test_field_type\NormalizerFile
-
core/
modules/ jsonapi/ tests/ modules/ jsonapi_test_field_type/ src/ Normalizer/ StringNormalizer.php
View source
<?php
namespace Drupal\jsonapi_test_field_type\Normalizer;
use Drupal\Core\Field\Plugin\Field\FieldType\StringItem;
use Drupal\serialization\Normalizer\FieldItemNormalizer;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
/**
* Normalizes string fields weirdly: replaces 'super' with 'NOT' and vice versa.
*/
class StringNormalizer extends FieldItemNormalizer implements DenormalizerInterface {
/**
* {@inheritdoc}
*/
public function normalize($object, $format = NULL, array $context = []) : array|string|int|float|bool|\ArrayObject|null {
$data = parent::normalize($object, $format, $context);
$data['value'] = str_replace('super', 'NOT', $data['value']);
return $data;
}
/**
* {@inheritdoc}
*/
protected function constructValue($data, $context) {
$data = parent::constructValue($data, $context);
$data['value'] = str_replace('NOT', 'super', $data['value']);
return $data;
}
/**
* {@inheritdoc}
*/
public function getSupportedTypes(?string $format) : array {
return [
StringItem::class => TRUE,
];
}
}
Classes
Title | Deprecated | Summary |
---|---|---|
StringNormalizer | Normalizes string fields 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.