You are here

public function ContentEntityNormalizer::normalize in Drupal 9

Same name in this branch
  1. 9 core/modules/hal/src/Normalizer/ContentEntityNormalizer.php \Drupal\hal\Normalizer\ContentEntityNormalizer::normalize()
  2. 9 core/modules/serialization/src/Normalizer/ContentEntityNormalizer.php \Drupal\serialization\Normalizer\ContentEntityNormalizer::normalize()
Same name and namespace in other branches
  1. 8 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;
}