Version 1
[yaffs-website] / web / core / modules / serialization / src / Normalizer / ContentEntityNormalizer.php
diff --git a/web/core/modules/serialization/src/Normalizer/ContentEntityNormalizer.php b/web/core/modules/serialization/src/Normalizer/ContentEntityNormalizer.php
new file mode 100644 (file)
index 0000000..f1ca82d
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+
+namespace Drupal\serialization\Normalizer;
+
+/**
+ * Normalizes/denormalizes Drupal content entities into an array structure.
+ */
+class ContentEntityNormalizer extends EntityNormalizer {
+
+  /**
+   * {@inheritdoc}
+   */
+  protected $supportedInterfaceOrClass = ['Drupal\Core\Entity\ContentEntityInterface'];
+
+  /**
+   * {@inheritdoc}
+   */
+  public function normalize($object, $format = NULL, array $context = []) {
+    $context += [
+      'account' => NULL,
+    ];
+
+    $attributes = [];
+    foreach ($object as $name => $field) {
+      if ($field->access('view', $context['account'])) {
+        $attributes[$name] = $this->serializer->normalize($field, $format, $context);
+      }
+    }
+
+    return $attributes;
+  }
+
+}