mirror of
https://github.com/kevinpapst/kimai2.git
synced 2025-05-12 12:42:00 +00:00
additional form types for simple usage in SystemConfiguration and UserPreferences
This commit is contained in:
parent
56c14b9935
commit
c78b392668
6 changed files with 198 additions and 0 deletions
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;
|
||||
}
|
||||
}
|
32
src/Form/Type/ActivityByIdType.php
Normal file
32
src/Form/Type/ActivityByIdType.php
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?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\Type;
|
||||
|
||||
use App\Form\DataTransformer\EntityByIdTransformer;
|
||||
use App\Repository\ActivityRepository;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
final class ActivityByIdType extends AbstractType
|
||||
{
|
||||
public function __construct(private readonly ActivityRepository $repository)
|
||||
{
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder->addModelTransformer(new EntityByIdTransformer($this->repository));
|
||||
}
|
||||
|
||||
public function getParent(): string
|
||||
{
|
||||
return ActivityType::class;
|
||||
}
|
||||
}
|
32
src/Form/Type/CustomerByIdType.php
Normal file
32
src/Form/Type/CustomerByIdType.php
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?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\Type;
|
||||
|
||||
use App\Form\DataTransformer\EntityByIdTransformer;
|
||||
use App\Repository\CustomerRepository;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
final class CustomerByIdType extends AbstractType
|
||||
{
|
||||
public function __construct(private readonly CustomerRepository $repository)
|
||||
{
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder->addModelTransformer(new EntityByIdTransformer($this->repository));
|
||||
}
|
||||
|
||||
public function getParent(): string
|
||||
{
|
||||
return CustomerType::class;
|
||||
}
|
||||
}
|
32
src/Form/Type/ProjectByIdType.php
Normal file
32
src/Form/Type/ProjectByIdType.php
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?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\Type;
|
||||
|
||||
use App\Form\DataTransformer\EntityByIdTransformer;
|
||||
use App\Repository\ProjectRepository;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
final class ProjectByIdType extends AbstractType
|
||||
{
|
||||
public function __construct(private readonly ProjectRepository $repository)
|
||||
{
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder->addModelTransformer(new EntityByIdTransformer($this->repository));
|
||||
}
|
||||
|
||||
public function getParent(): string
|
||||
{
|
||||
return ProjectType::class;
|
||||
}
|
||||
}
|
32
src/Form/Type/TeamByIdType.php
Normal file
32
src/Form/Type/TeamByIdType.php
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?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\Type;
|
||||
|
||||
use App\Form\DataTransformer\EntityByIdTransformer;
|
||||
use App\Repository\TeamRepository;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
final class TeamByIdType extends AbstractType
|
||||
{
|
||||
public function __construct(private readonly TeamRepository $repository)
|
||||
{
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder->addModelTransformer(new EntityByIdTransformer($this->repository));
|
||||
}
|
||||
|
||||
public function getParent(): string
|
||||
{
|
||||
return TeamType::class;
|
||||
}
|
||||
}
|
32
src/Form/Type/UserByIdType.php
Normal file
32
src/Form/Type/UserByIdType.php
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?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\Type;
|
||||
|
||||
use App\Form\DataTransformer\EntityByIdTransformer;
|
||||
use App\Repository\UserRepository;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
final class UserByIdType extends AbstractType
|
||||
{
|
||||
public function __construct(private readonly UserRepository $repository)
|
||||
{
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder->addModelTransformer(new EntityByIdTransformer($this->repository));
|
||||
}
|
||||
|
||||
public function getParent(): string
|
||||
{
|
||||
return UserType::class;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue