You are here

public function FieldItemNormalizer::normalize in Zircon Profile 8

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

Normalizes an object into a set of arrays/scalars.

Parameters

object $object object to normalize:

string $format format the normalization result will be encoded as:

array $context Context options for the normalizer:

Return value

array|string|bool|int|float|null

Overrides NormalizerInterface::normalize

1 call to FieldItemNormalizer::normalize()
EntityReferenceItemNormalizer::normalize in core/modules/hal/src/Normalizer/EntityReferenceItemNormalizer.php
Normalizes an object into a set of arrays/scalars.
1 method overrides FieldItemNormalizer::normalize()
EntityReferenceItemNormalizer::normalize in core/modules/hal/src/Normalizer/EntityReferenceItemNormalizer.php
Normalizes an object into a set of arrays/scalars.

File

core/modules/hal/src/Normalizer/FieldItemNormalizer.php, line 28
Contains \Drupal\hal\Normalizer\FieldItemNormalizer.

Class

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

Namespace

Drupal\hal\Normalizer

Code

public function normalize($field_item, $format = NULL, array $context = array()) {
  $values = $field_item
    ->toArray();
  if (isset($context['langcode'])) {
    $values['lang'] = $context['langcode'];
  }

  // The values are wrapped in an array, and then wrapped in another array
  // keyed by field name so that field items can be merged by the
  // FieldNormalizer. This is necessary for the EntityReferenceItemNormalizer
  // to be able to place values in the '_links' array.
  $field = $field_item
    ->getParent();
  return array(
    $field
      ->getName() => array(
      $values,
    ),
  );
}