protected function ResourceObjectToEntityMapper::mapResourceObjectToEntity in JSON:API Resources 8
Builds an array of values to use to create an entity.
Parameters
\Drupal\jsonapi\JsonApiResource\ResourceObject $resource_object: The resource object from which to map values.
Return value
\Drupal\Core\Entity\ContentEntityInterface A new entity created from a resource object.
Throws
\UnexpectedValueException Thrown when the resource object does not represent an entity.
\Symfony\Component\HttpKernel\Exception\HttpException Thrown when the resource object represents a config entity.
See also
\Drupal\Core\Entity\EntityStorageInterface::create()
1 call to ResourceObjectToEntityMapper::mapResourceObjectToEntity()
- ResourceObjectToEntityMapper::createEntityFromResourceObject in src/
Unstable/ Entity/ ResourceObjectToEntityMapper.php - Creates a new entity from the given resource object.
File
- src/
Unstable/ Entity/ ResourceObjectToEntityMapper.php, line 73
Class
- ResourceObjectToEntityMapper
- Service which maps a resource object into an entity.
Namespace
Drupal\jsonapi_resources\Unstable\EntityCode
protected function mapResourceObjectToEntity(ResourceObject $resource_object) : EntityInterface {
$target_class = $resource_object
->getResourceType()
->getDeserializationTargetClass();
if (in_array(ContentEntityInterface::class, class_implements($target_class, TRUE) ?: [])) {
return $this
->mapResourceObjectToContentEntity($resource_object);
}
elseif (in_array(ConfigEntityInterface::class, class_implements($target_class, TRUE) ?: [])) {
throw new HttpException(501, 'The JSON:API Resources module does not yet support config entity mutation.');
}
else {
throw new \UnexpectedValueException('The given resource object does not represent a content or config entity.');
}
}