function TextItemSillyNormalizer::constructValue

Same name and namespace in other branches
  1. 9 core/modules/serialization/tests/modules/field_normalization_test/src/Normalization/TextItemSillyNormalizer.php \Drupal\field_normalization_test\Normalization\TextItemSillyNormalizer::constructValue()
  2. 8.9.x core/modules/serialization/tests/modules/field_normalization_test/src/Normalization/TextItemSillyNormalizer.php \Drupal\field_normalization_test\Normalization\TextItemSillyNormalizer::constructValue()
  3. 10 core/modules/serialization/tests/modules/field_normalization_test/src/Normalization/TextItemSillyNormalizer.php \Drupal\field_normalization_test\Normalization\TextItemSillyNormalizer::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 re-implementing 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 \Drupal\Core\Field\FieldItemBase::setValue() or a subclass.

Overrides FieldableEntityNormalizerTrait::constructValue

File

core/modules/serialization/tests/modules/field_normalization_test/src/Normalization/TextItemSillyNormalizer.php, line 27

Class

TextItemSillyNormalizer
A test TextItem normalizer to test denormalization.

Namespace

Drupal\field_normalization_test\Normalization

Code

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

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