function ContentEntityNormalizer::normalize

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

Normalizes data into a set of arrays/scalars.

Parameters

object $entity: Data to normalize.

string|null $format: Format the normalization result will be encoded as.

array<string, mixed> $context: Context options for the normalizer.

Return value

array The normalized data.

Overrides ComplexDataNormalizer::normalize

File

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

Class

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

Namespace

Drupal\serialization\Normalizer

Code

public function normalize($entity, $format = NULL, array $context = []) : array {
  $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.