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