function FieldNormalizer::normalizeFieldItems

Same name in other branches
  1. 9 core/modules/jsonapi/src/Normalizer/FieldNormalizer.php \Drupal\jsonapi\Normalizer\FieldNormalizer::normalizeFieldItems()
  2. 9 core/modules/hal/src/Normalizer/FieldNormalizer.php \Drupal\hal\Normalizer\FieldNormalizer::normalizeFieldItems()
  3. 8.9.x core/modules/jsonapi/src/Normalizer/FieldNormalizer.php \Drupal\jsonapi\Normalizer\FieldNormalizer::normalizeFieldItems()
  4. 8.9.x core/modules/hal/src/Normalizer/FieldNormalizer.php \Drupal\hal\Normalizer\FieldNormalizer::normalizeFieldItems()
  5. 11.x core/modules/jsonapi/src/Normalizer/FieldNormalizer.php \Drupal\jsonapi\Normalizer\FieldNormalizer::normalizeFieldItems()

Helper function to normalize field items.

Parameters

\Drupal\Core\Field\FieldItemListInterface $field: The field object.

string $format: The format.

array $context: The context array.

Return value

\Drupal\jsonapi\Normalizer\FieldItemNormalizer[] The array of normalized field items.

1 call to FieldNormalizer::normalizeFieldItems()
FieldNormalizer::normalize in core/modules/jsonapi/src/Normalizer/FieldNormalizer.php

File

core/modules/jsonapi/src/Normalizer/FieldNormalizer.php, line 82

Class

FieldNormalizer
Converts the Drupal field structure to a JSON:API array structure.

Namespace

Drupal\jsonapi\Normalizer

Code

protected function normalizeFieldItems(FieldItemListInterface $field, $format, array $context) {
    $normalizer_items = [];
    if (!$field->isEmpty()) {
        foreach ($field as $field_item) {
            $normalizer_items[] = $this->serializer
                ->normalize($field_item, $format, $context);
        }
    }
    return $normalizer_items;
}

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