public function FieldItemNormalizer::normalize

Implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface::normalize()

Overrides NormalizerInterface::normalize

1 method overrides FieldItemNormalizer::normalize()

File

drupal/core/modules/hal/lib/Drupal/hal/Normalizer/FieldItemNormalizer.php, line 27
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
    ->getPropertyValues();
  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,
    ),
  );
}