You are here

public function ComplexDataDefinitionNormalizer::normalize in Schemata 8

Same name in this branch
  1. 8 schemata_json_schema/src/Normalizer/jsonapi/ComplexDataDefinitionNormalizer.php \Drupal\schemata_json_schema\Normalizer\jsonapi\ComplexDataDefinitionNormalizer::normalize()
  2. 8 schemata_json_schema/src/Normalizer/json/ComplexDataDefinitionNormalizer.php \Drupal\schemata_json_schema\Normalizer\json\ComplexDataDefinitionNormalizer::normalize()
  3. 8 schemata_json_schema/src/Normalizer/hal/ComplexDataDefinitionNormalizer.php \Drupal\schemata_json_schema\Normalizer\hal\ComplexDataDefinitionNormalizer::normalize()

Overrides ComplexDataDefinitionNormalizer::normalize

File

schemata_json_schema/src/Normalizer/hal/ComplexDataDefinitionNormalizer.php, line 29

Class

ComplexDataDefinitionNormalizer
Normalizer for ComplexDataDefinitionInterface for HAL.

Namespace

Drupal\schemata_json_schema\Normalizer\hal

Code

public function normalize($entity, $format = NULL, array $context = []) {

  /* @var $entity \Drupal\Core\TypedData\ComplexDataDefinitionInterface */

  // If this does not wrap a reference, revert to standard JSON behavior.
  if (!$this
    ->isReferenceField($entity, $context)) {
    return parent::normalize($entity, $format, $context);
  }

  // Not overriding the $context['parent'] here allows trickle-down of
  // top-level field labels. However, we do need some of the field settings.
  $context['settings'] = $entity
    ->getSettings();
  return $this->serializer
    ->normalize($entity
    ->getPropertyDefinition('entity'), $format, $context);
}