You are here

protected function FieldItemNormalizer::normalizedFieldValues in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/hal/src/Normalizer/FieldItemNormalizer.php \Drupal\hal\Normalizer\FieldItemNormalizer::normalizedFieldValues()

Normalizes field values for an item.

Parameters

\Drupal\Core\Field\FieldItemInterface $field_item: The field item instance.

string|null $format: The normalization format.

array $context: The context passed into the normalizer.

Return value

array An array of field item values, keyed by property name.

3 calls to FieldItemNormalizer::normalizedFieldValues()
EntityReferenceItemNormalizer::normalizedFieldValues in core/modules/hal/src/Normalizer/EntityReferenceItemNormalizer.php
Normalizes field values for an item.
FieldItemNormalizer::normalize in core/modules/hal/src/Normalizer/FieldItemNormalizer.php
TimestampItemNormalizer::normalizedFieldValues in core/modules/hal/src/Normalizer/TimestampItemNormalizer.php
Normalizes field values for an item.
2 methods override FieldItemNormalizer::normalizedFieldValues()
EntityReferenceItemNormalizer::normalizedFieldValues in core/modules/hal/src/Normalizer/EntityReferenceItemNormalizer.php
Normalizes field values for an item.
TimestampItemNormalizer::normalizedFieldValues in core/modules/hal/src/Normalizer/TimestampItemNormalizer.php
Normalizes field values for an item.

File

core/modules/hal/src/Normalizer/FieldItemNormalizer.php, line 79

Class

FieldItemNormalizer
Converts the Drupal field item object structure to HAL array structure.

Namespace

Drupal\hal\Normalizer

Code

protected function normalizedFieldValues(FieldItemInterface $field_item, $format, array $context) {
  $normalized = [];

  // We normalize each individual property, so each can do their own casting,
  // if needed.

  /** @var \Drupal\Core\TypedData\TypedDataInterface $property */
  $field_properties = !empty($field_item
    ->getProperties(TRUE)) ? TypedDataInternalPropertiesHelper::getNonInternalProperties($field_item) : $field_item
    ->getValue();
  foreach ($field_properties as $property_name => $property) {
    $normalized[$property_name] = $this->serializer
      ->normalize($property, $format, $context);
  }
  if (isset($context['langcode'])) {
    $normalized['lang'] = $context['langcode'];
  }
  return $normalized;
}