Release 2.30 (#5345)
- added missing InvoiceTemplate company, title) field validator - graceful fallback for missing working-contract mode - improve email test command (use configured MAIL_FROM) - additional form types for simple usage in SystemConfiguration and UserPreferences - allow to extend the working time query via event
This commit is contained in:
38
src/Form/DataTransformer/EntityByIdTransformer.php
Normal file
38
src/Form/DataTransformer/EntityByIdTransformer.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Form\DataTransformer;
|
||||
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Symfony\Component\Form\DataTransformerInterface;
|
||||
|
||||
final class EntityByIdTransformer implements DataTransformerInterface // @phpstan-ignore missingType.generics
|
||||
{
|
||||
public function __construct(private readonly EntityRepository $repository) // @phpstan-ignore missingType.generics
|
||||
{
|
||||
}
|
||||
|
||||
public function transform(mixed $value): mixed
|
||||
{
|
||||
if (is_numeric($value)) {
|
||||
return $this->repository->find($value);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function reverseTransform(mixed $value): mixed
|
||||
{
|
||||
if (\is_object($value) && method_exists($value, 'getId') && $value->getId() !== null) {
|
||||
return (string) $value->getId();
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user