public function JsonldEntityReferenceNormalizer::normalize

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

Overrides NormalizerInterface::normalize

File

drupal/core/modules/jsonld/lib/Drupal/jsonld/JsonldEntityReferenceNormalizer.php, line 22
Definition of Drupal\jsonld\JsonldEntityReferenceNormalizer.

Class

JsonldEntityReferenceNormalizer
Converts an EntityReferenceItem to a JSON-LD array structure.

Namespace

Drupal\jsonld

Code

public function normalize($object, $format = NULL) {

  // @todo If an $options parameter is added to the serialize signature, as
  // requested in https://github.com/symfony/symfony/pull/4938, then instead
  // of creating the array of properties, we could simply call normalize and
  // pass in the referenced entity with a flag that ensures it is rendered as
  // a node reference and not a node definition.
  $entityWrapper = new JsonldEntityWrapper($object->entity, $format, $this->serializer);
  return array(
    '@id' => $entityWrapper
      ->getId(),
  );
}