d3abef6f128a7d07ad258b3665bf792b55f46d82
[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($entity, $format = NULL, array $context = []) {
19     $context += [
20       'account' => NULL,
21     ];
22
23     $attributes = [];
24     foreach ($entity as $name => $field_items) {
25       if ($field_items->access('view', $context['account'])) {
26         $attributes[$name] = $this->serializer->normalize($field_items, $format, $context);
27       }
28     }
29
30     return $attributes;
31   }
32
33 }