class JsonldEntityNormalizer

Converts the Drupal entity object structure to JSON-LD array structure.

Hierarchy

Expanded class hierarchy of JsonldEntityNormalizer

1 file declares its use of JsonldEntityNormalizer
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/JsonldEntityNormalizer.php, line 17
Definition of Drupal\jsonld\JsonldEntityNormalizer.

Namespace

Drupal\jsonld
View source
class JsonldEntityNormalizer extends JsonldNormalizerBase {

  /**
   * Implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface::normalize()
   */
  public function normalize($entity, $format = NULL) {
    $entityWrapper = new JsonldEntityWrapper($entity, $format, $this->serializer);
    $attributes = $entityWrapper
      ->getProperties();
    $attributes = array(
      '@id' => $entityWrapper
        ->getId(),
    ) + $attributes;
    return $attributes;
  }

  /**
   * Implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface::supportsNormalization()
   */
  public function supportsNormalization($data, $format = NULL) {

    // @todo Switch to EntityInterface once all entity types are converted to
    // EntityNG.
    return parent::supportsNormalization($data, $format) && $data instanceof EntityNG;
  }

}

Members