You are here

protected function ResourceObjectToEntityMapper::mapResourceObjectToContentEntity in JSON:API Resources 8

Builds an array of values to use to create a content entity.

Copied from JSON:API code. Modify with extreme care.

Parameters

\Drupal\jsonapi\JsonApiResource\ResourceObject $resource_object: The resource object from which to create a new entity.

Return value

\Drupal\Core\Entity\ContentEntityInterface A new entity created from a resource object.

See also

\Drupal\jsonapi\Normalizer\ContentEntityDenormalizer::prepareInput()

1 call to ResourceObjectToEntityMapper::mapResourceObjectToContentEntity()
ResourceObjectToEntityMapper::mapResourceObjectToEntity in src/Unstable/Entity/ResourceObjectToEntityMapper.php
Builds an array of values to use to create an entity.

File

src/Unstable/Entity/ResourceObjectToEntityMapper.php, line 99

Class

ResourceObjectToEntityMapper
Service which maps a resource object into an entity.

Namespace

Drupal\jsonapi_resources\Unstable\Entity

Code

protected function mapResourceObjectToContentEntity(ResourceObject $resource_object) : ContentEntityInterface {
  $resource_type = $resource_object
    ->getResourceType();
  return $this->serializer
    ->denormalize($resource_object
    ->getFields(), $resource_type
    ->getDeserializationTargetClass(), 'api_json', [
    'resource_type' => $resource_type,
  ]);
}