You are here

protected function FieldableEntityNormalizerTrait::getEntityTypeDefinition in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/serialization/src/Normalizer/FieldableEntityNormalizerTrait.php \Drupal\serialization\Normalizer\FieldableEntityNormalizerTrait::getEntityTypeDefinition()
  2. 10 core/modules/serialization/src/Normalizer/FieldableEntityNormalizerTrait.php \Drupal\serialization\Normalizer\FieldableEntityNormalizerTrait::getEntityTypeDefinition()

Gets the entity type definition.

Parameters

string $entity_type_id: The entity type ID to load the definition for.

Return value

\Drupal\Core\Entity\EntityTypeInterface The loaded entity type definition.

Throws

\Symfony\Component\Serializer\Exception\UnexpectedValueException

2 calls to FieldableEntityNormalizerTrait::getEntityTypeDefinition()
ContentEntityNormalizer::denormalize in core/modules/hal/src/Normalizer/ContentEntityNormalizer.php
Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::denormalize().
EntityNormalizer::denormalize in core/modules/serialization/src/Normalizer/EntityNormalizer.php

File

core/modules/serialization/src/Normalizer/FieldableEntityNormalizerTrait.php, line 68

Class

FieldableEntityNormalizerTrait
A trait for providing fieldable entity normalization/denormalization methods.

Namespace

Drupal\serialization\Normalizer

Code

protected function getEntityTypeDefinition($entity_type_id) {

  /** @var \Drupal\Core\Entity\EntityTypeInterface $entity_type_definition */

  // Get the entity type definition.
  $entity_type_definition = $this
    ->getEntityTypeManager()
    ->getDefinition($entity_type_id, FALSE);

  // Don't try to create an entity without an entity type id.
  if (!$entity_type_definition) {
    throw new UnexpectedValueException(sprintf('The specified entity type "%s" does not exist. A valid entity type is required for denormalization', $entity_type_id));
  }
  return $entity_type_definition;
}