You are here

class ContentEntityNormalizer in Drupal 9

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

}

Members

Namesort descending Modifiers Type Description Overrides
CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY constant Name of key for bubbling cacheability metadata via serialization context.
ContentEntityNormalizer::$supportedInterfaceOrClass protected property The interface or class that this Normalizer supports. Overrides EntityNormalizer::$supportedInterfaceOrClass
ContentEntityNormalizer::normalize public function Overrides ComplexDataNormalizer::normalize
EntityNormalizer::denormalize public function 1
EntityNormalizer::__construct public function Constructs an EntityNormalizer object.
FieldableEntityNormalizerTrait::$entityFieldManager protected property The entity field manager.
FieldableEntityNormalizerTrait::$entityTypeManager protected property The entity type manager. 1
FieldableEntityNormalizerTrait::$entityTypeRepository protected property The entity type repository.
FieldableEntityNormalizerTrait::constructValue protected function Build the field item value using the incoming data. 7
FieldableEntityNormalizerTrait::denormalizeFieldData protected function Denormalizes entity data by denormalizing each field individually.
FieldableEntityNormalizerTrait::determineEntityTypeId protected function Determines the entity type ID to denormalize as.
FieldableEntityNormalizerTrait::extractBundleData protected function Denormalizes the bundle property so entity creation can use it.
FieldableEntityNormalizerTrait::getEntityFieldManager protected function Returns the entity field manager.
FieldableEntityNormalizerTrait::getEntityTypeDefinition protected function Gets the entity type definition.
FieldableEntityNormalizerTrait::getEntityTypeManager protected function Returns the entity type manager.
FieldableEntityNormalizerTrait::getEntityTypeRepository protected function Returns the entity type repository.
NormalizerBase::$format protected property List of formats which supports (de-)normalization. 3
NormalizerBase::addCacheableDependency protected function Adds cacheability if applicable.
NormalizerBase::checkFormat protected function Checks if the provided format is supported by this normalizer. 1
NormalizerBase::supportsDenormalization public function Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::supportsDenormalization() 1
NormalizerBase::supportsNormalization public function 1