function ContentEntityNormalizer::normalize

Same name in this branch
  1. 8.9.x core/modules/hal/src/Normalizer/ContentEntityNormalizer.php \Drupal\hal\Normalizer\ContentEntityNormalizer::normalize()
Same name in other branches
  1. 9 core/modules/serialization/src/Normalizer/ContentEntityNormalizer.php \Drupal\serialization\Normalizer\ContentEntityNormalizer::normalize()
  2. 9 core/modules/hal/src/Normalizer/ContentEntityNormalizer.php \Drupal\hal\Normalizer\ContentEntityNormalizer::normalize()
  3. 10 core/modules/serialization/src/Normalizer/ContentEntityNormalizer.php \Drupal\serialization\Normalizer\ContentEntityNormalizer::normalize()
  4. 11.x core/modules/serialization/src/Normalizer/ContentEntityNormalizer.php \Drupal\serialization\Normalizer\ContentEntityNormalizer::normalize()

Overrides ComplexDataNormalizer::normalize

File

core/modules/serialization/src/Normalizer/ContentEntityNormalizer.php, line 21

Class

ContentEntityNormalizer
Normalizes/denormalizes Drupal content entities into an array structure.

Namespace

Drupal\serialization\Normalizer

Code

public function normalize($entity, $format = NULL, array $context = []) {
    $context += [
        'account' => NULL,
    ];
    $attributes = [];
    
    /** @var \Drupal\Core\Entity\Entity $entity */
    foreach (TypedDataInternalPropertiesHelper::getNonInternalProperties($entity->getTypedData()) as $name => $field_items) {
        if ($field_items->access('view', $context['account'])) {
            $attributes[$name] = $this->serializer
                ->normalize($field_items, $format, $context);
        }
    }
    return $attributes;
}

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