public function FieldNormalizer::normalize in Drupal 9
Same name in this branch
- 9 core/modules/jsonapi/src/Normalizer/FieldNormalizer.php \Drupal\jsonapi\Normalizer\FieldNormalizer::normalize()
- 9 core/modules/hal/src/Normalizer/FieldNormalizer.php \Drupal\hal\Normalizer\FieldNormalizer::normalize()
Same name and namespace in other branches
- 8 core/modules/jsonapi/src/Normalizer/FieldNormalizer.php \Drupal\jsonapi\Normalizer\FieldNormalizer::normalize()
1 method overrides FieldNormalizer::normalize()
- EntityReferenceFieldNormalizer::normalize in core/
modules/ jsonapi/ src/ Normalizer/ EntityReferenceFieldNormalizer.php
File
- core/
modules/ jsonapi/ src/ Normalizer/ FieldNormalizer.php, line 33
Class
- FieldNormalizer
- Converts the Drupal field structure to a JSON:API array structure.
Namespace
Drupal\jsonapi\NormalizerCode
public function normalize($field, $format = NULL, array $context = []) {
/** @var \Drupal\Core\Field\FieldItemListInterface $field */
$normalized_items = $this
->normalizeFieldItems($field, $format, $context);
assert($context['resource_object'] instanceof ResourceObject);
return $context['resource_object']
->getResourceType()
->getFieldByInternalName($field
->getName())
->hasOne() ? array_shift($normalized_items) ?: CacheableNormalization::permanent(NULL) : CacheableNormalization::aggregate($normalized_items);
}