You are here

protected function StringNormalizer::constructValue in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/jsonapi/tests/modules/jsonapi_test_field_type/src/Normalizer/StringNormalizer.php \Drupal\jsonapi_test_field_type\Normalizer\StringNormalizer::constructValue()

Build the field item value using the incoming data.

Most normalizers that extend this class can simply use this method to construct the denormalized value without having to override denormalize() and reimplementing its validation logic or its call to set the field value.

It's recommended to not override this and instead provide a (de)normalizer at the DataType level.

Parameters

mixed $data: The incoming data for this field item.

array $context: The context passed into the Normalizer.

Return value

mixed The value to use in Entity::setValue().

Overrides FieldableEntityNormalizerTrait::constructValue

File

core/modules/jsonapi/tests/modules/jsonapi_test_field_type/src/Normalizer/StringNormalizer.php, line 31

Class

StringNormalizer
Normalizes string fields weirdly: replaces 'super' with 'NOT' and vice versa.

Namespace

Drupal\jsonapi_test_field_type\Normalizer

Code

protected function constructValue($data, $context) {
  $data = parent::constructValue($data, $context);
  $data['value'] = str_replace('NOT', 'super', $data['value']);
  return $data;
}