3d2031218f1bef4611012c075cf6529eb8aee7e9
[yaffs-website] / web / core / modules / serialization / src / Normalizer / ComplexDataNormalizer.php
1 <?php
2
3 namespace Drupal\serialization\Normalizer;
4
5 /**
6  * Converts the Drupal entity object structures to a normalized array.
7  *
8  * This is the default Normalizer for entities. All formats that have Encoders
9  * registered with the Serializer in the DIC will be normalized with this
10  * class unless another Normalizer is registered which supersedes it. If a
11  * module wants to use format-specific or class-specific normalization, then
12  * that module can register a new Normalizer and give it a higher priority than
13  * this one.
14  */
15 class ComplexDataNormalizer extends NormalizerBase {
16
17   /**
18    * The interface or class that this Normalizer supports.
19    *
20    * @var string
21    */
22   protected $supportedInterfaceOrClass = 'Drupal\Core\TypedData\ComplexDataInterface';
23
24   /**
25    * {@inheritdoc}
26    */
27   public function normalize($object, $format = NULL, array $context = []) {
28     $attributes = [];
29     /** @var \Drupal\Core\TypedData\TypedDataInterface $field */
30     foreach ($object as $name => $field) {
31       $attributes[$name] = $this->serializer->normalize($field, $format, $context);
32     }
33     return $attributes;
34   }
35
36 }