WIP: Implement profile editing

This commit is contained in:
Björn Fromme
2023-10-02 12:39:52 +02:00
parent d776d37cd5
commit 953aa9c8e0
27 changed files with 598 additions and 43 deletions
@@ -0,0 +1,38 @@
<?php
namespace App\Form\DataTransformer;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\TransformationFailedException;
class EntityToIdTransformer implements DataTransformerInterface
{
public function __construct(private readonly EntityManagerInterface $entityManager, private readonly string $class)
{
}
public function transform($value)
{
if (null === $value) {
return null;
}
return $value->getId();
}
public function reverseTransform($value)
{
if (empty($value)) {
return null;
}
$entity = $this->entityManager->getRepository($this->class)->find($value);
if (null === $entity) {
throw new TransformationFailedException(sprintf('No %s with id %d found', $this->class, $value));
}
return $entity;
}
}