Version 1
[yaffs-website] / web / core / modules / serialization / src / Normalizer / ContentEntityNormalizer.php
1 <?php
2
3 namespace Drupal\serialization\Normalizer;
4
5 /**
6  * Normalizes/denormalizes Drupal content entities into an array structure.
7  */
8 class ContentEntityNormalizer extends EntityNormalizer {
9
10   /**
11    * {@inheritdoc}
12    */
13   protected $supportedInterfaceOrClass = ['Drupal\Core\Entity\ContentEntityInterface'];
14
15   /**
16    * {@inheritdoc}
17    */
18   public function normalize($object, $format = NULL, array $context = []) {
19     $context += [
20       'account' => NULL,
21     ];
22
23     $attributes = [];
24     foreach ($object as $name => $field) {
25       if ($field->access('view', $context['account'])) {
26         $attributes[$name] = $this->serializer->normalize($field, $format, $context);
27       }
28     }
29
30     return $attributes;
31   }
32
33 }