Using Api Platform, I have a problem using an input class and its transformation.
The following documentation has been followed. https://api-platform.com/docs/core/dto/#using-data-transfer-objects-dtos
After Data Transformer service executes transformation and returns an object of the correct class, the object that is picked up by api-platform appears to be empty, so it either fails validation, if validation is present, or persistence to the database fails - due its fields appear to be empty.
Here is a simplified code of DataTransformer service methods - it produces an object with hardcoded values:
public function transform($object, string $to, array $context = [])
{
$newCreativeElement = new CreativeElement();
$newCreativeElement->setKeyName("HARDCODED VALUE");
$newCreativeElement->setIntValue(42);
return $newCreativeElement;
}
public function supportsTransformation($object, string $to, array $context = []): bool
{
if ($object instanceof CreativeElement){
return false;
}
$result = CreativeElement::class === $to && null !== ($context['input']['class'] ?? null);
return $result;
}