class ContentEntityNormalizer

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

Normalizes/denormalizes Drupal content entities into an array structure.

Hierarchy

Expanded class hierarchy of ContentEntityNormalizer

1 file declares its use of ContentEntityNormalizer
ContentEntityNormalizerTest.php in core/modules/serialization/tests/src/Unit/Normalizer/ContentEntityNormalizerTest.php
1 string reference to 'ContentEntityNormalizer'
serialization.services.yml in core/modules/serialization/serialization.services.yml
core/modules/serialization/serialization.services.yml
1 service uses ContentEntityNormalizer
serializer.normalizer.content_entity in core/modules/serialization/serialization.services.yml
Drupal\serialization\Normalizer\ContentEntityNormalizer

File

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

Namespace

Drupal\serialization\Normalizer
View source
class ContentEntityNormalizer extends EntityNormalizer {
  
  /**
   * {@inheritdoc}
   */
  protected $supportedInterfaceOrClass = ContentEntityInterface::class;
  
  /**
   * {@inheritdoc}
   */
  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.