class JsonldEntityReferenceNormalizer

Converts an EntityReferenceItem to a JSON-LD array structure.

Hierarchy

Expanded class hierarchy of JsonldEntityReferenceNormalizer

1 file declares its use of JsonldEntityReferenceNormalizer
DrupalJsonldNormalizerTest.php in drupal/core/modules/jsonld/lib/Drupal/jsonld/Tests/DrupalJsonldNormalizerTest.php
Definition of Drupal\jsonld\Tests\DrupalJsonldNormalizerTest.

File

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

Namespace

Drupal\jsonld
View source
class JsonldEntityReferenceNormalizer extends JsonldNormalizerBase {

  /**
   * Implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface::normalize()
   */
  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(),
    );
  }

  /**
   * Implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface::supportsNormalization()
   */
  public function supportsNormalization($data, $format = NULL) {
    return parent::supportsNormalization($data, $format) && $data instanceof EntityReferenceItem;
  }

}

Members