function ComplexDataNormalizer::normalize

Same name in other branches
  1. 9 core/modules/serialization/src/Normalizer/ComplexDataNormalizer.php \Drupal\serialization\Normalizer\ComplexDataNormalizer::normalize()
  2. 10 core/modules/serialization/src/Normalizer/ComplexDataNormalizer.php \Drupal\serialization\Normalizer\ComplexDataNormalizer::normalize()
  3. 11.x core/modules/serialization/src/Normalizer/ComplexDataNormalizer.php \Drupal\serialization\Normalizer\ComplexDataNormalizer::normalize()
5 calls to ComplexDataNormalizer::normalize()
BooleanItemNormalizer::normalize in core/modules/serialization/tests/modules/test_fieldtype_boolean_emoji_normalizer/src/Normalizer/BooleanItemNormalizer.php
EntityReferenceFieldItemNormalizer::normalize in core/modules/serialization/src/Normalizer/EntityReferenceFieldItemNormalizer.php
StringNormalizer::normalize in core/modules/jsonapi/tests/modules/jsonapi_test_field_type/src/Normalizer/StringNormalizer.php
TextItemSillyNormalizer::normalize in core/modules/serialization/tests/modules/field_normalization_test/src/Normalization/TextItemSillyNormalizer.php
TimestampItemNormalizer::normalize in core/modules/serialization/src/Normalizer/TimestampItemNormalizer.php
7 methods override ComplexDataNormalizer::normalize()
BooleanItemNormalizer::normalize in core/modules/serialization/tests/modules/test_fieldtype_boolean_emoji_normalizer/src/Normalizer/BooleanItemNormalizer.php
ConfigEntityNormalizer::normalize in core/modules/serialization/src/Normalizer/ConfigEntityNormalizer.php
ContentEntityNormalizer::normalize in core/modules/serialization/src/Normalizer/ContentEntityNormalizer.php
EntityReferenceFieldItemNormalizer::normalize in core/modules/serialization/src/Normalizer/EntityReferenceFieldItemNormalizer.php
StringNormalizer::normalize in core/modules/jsonapi/tests/modules/jsonapi_test_field_type/src/Normalizer/StringNormalizer.php

... See full list

File

core/modules/serialization/src/Normalizer/ComplexDataNormalizer.php, line 28

Class

ComplexDataNormalizer
Converts the Drupal entity object structures to a normalized array.

Namespace

Drupal\serialization\Normalizer

Code

public function normalize($object, $format = NULL, array $context = []) {
    $attributes = [];
    // $object will not always match $supportedInterfaceOrClass.
    // @see \Drupal\serialization\Normalizer\EntityNormalizer
    // Other normalizers that extend this class may only provide $object that
    // implements \Traversable.
    if ($object instanceof ComplexDataInterface) {
        // If there are no properties to normalize, just normalize the value.
        $object = !empty($object->getProperties(TRUE)) ? TypedDataInternalPropertiesHelper::getNonInternalProperties($object) : $object->getValue();
    }
    
    /** @var \Drupal\Core\TypedData\TypedDataInterface $property */
    foreach ($object as $name => $property) {
        $attributes[$name] = $this->serializer
            ->normalize($property, $format, $context);
    }
    return $attributes;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.