JsonldFieldItemNormalizer.php 895 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php

/**
 * @file
 * Definition of Drupal\jsonld\JsonldFieldItemNormalizer.
 */

namespace Drupal\jsonld;

use Drupal\Core\Entity\Field\FieldItemInterface;
use Drupal\jsonld\JsonldNormalizerBase;
use Symfony\Component\Serializer\Exception\RuntimeException;

/**
 * Converts the Drupal entity object structure to JSON-LD array structure.
 */
class JsonldFieldItemNormalizer extends JsonldNormalizerBase {

  /**
   * Implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface::normalize()
   */
  public function normalize($object, $format = NULL) {
    return $object->getPropertyValues();
  }

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

}