Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / serialization / src / Normalizer / ComplexDataNormalizer.php
index 33beb373a136b27331e15a44a18b7c2c19b5873f..e4fcf52b79ce3dfab813f98a77093f19d754b044 100644 (file)
@@ -2,6 +2,9 @@
 
 namespace Drupal\serialization\Normalizer;
 
+use Drupal\Core\TypedData\ComplexDataInterface;
+use Drupal\Core\TypedData\TypedDataInternalPropertiesHelper;
+
 /**
  * Converts the Drupal entity object structures to a normalized array.
  *
@@ -26,6 +29,13 @@ class ComplexDataNormalizer extends NormalizerBase {
    */
   public function normalize($object, $format = NULL, array $context = []) {
     $attributes = [];
+    // $object will not always match $supportedInterfaceOrClass.
+    // @see \Drupal\serialization\Normalizer\EntityNormalizer
+    // Other normalizers that extend this class may only provide $object that
+    // implements \Traversable.
+    if ($object instanceof ComplexDataInterface) {
+      $object = TypedDataInternalPropertiesHelper::getNonInternalProperties($object);
+    }
     /** @var \Drupal\Core\TypedData\TypedDataInterface $property */
     foreach ($object as $name => $property) {
       $attributes[$name] = $this->serializer->normalize($property, $format, $context);