|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
/** |
|
4
|
|
|
* /src/Form/Type/Console/ApiKeyType.php |
|
5
|
|
|
* |
|
6
|
|
|
* @author TLe, Tarmo Leppänen <[email protected]> |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace App\Form\Type\Console; |
|
10
|
|
|
|
|
11
|
|
|
use App\DTO\ApiKey\ApiKey; |
|
12
|
|
|
use App\Form\DataTransformer\UserGroupTransformer; |
|
13
|
|
|
use App\Form\Type\FormTypeLabelInterface; |
|
14
|
|
|
use App\Form\Type\Traits\AddBasicFieldToForm; |
|
15
|
|
|
use App\Form\Type\Traits\UserGroupChoices; |
|
16
|
|
|
use App\Resource\UserGroupResource; |
|
17
|
|
|
use Symfony\Component\Form\AbstractType; |
|
18
|
|
|
use Symfony\Component\Form\Extension\Core\Type; |
|
19
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
|
20
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
|
21
|
|
|
use Throwable; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Class ApiKeyType |
|
25
|
|
|
* |
|
26
|
|
|
* @psalm-suppress MissingTemplateParam |
|
27
|
|
|
* |
|
28
|
|
|
* @package App\Form\Type\Console |
|
29
|
|
|
* @author TLe, Tarmo Leppänen <[email protected]> |
|
30
|
|
|
*/ |
|
31
|
|
|
class ApiKeyType extends AbstractType |
|
32
|
|
|
{ |
|
33
|
|
|
use AddBasicFieldToForm; |
|
34
|
|
|
use UserGroupChoices; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Base form fields |
|
38
|
|
|
* |
|
39
|
|
|
* @var array<int, array<int, mixed>> |
|
40
|
|
|
*/ |
|
41
|
|
|
private static array $formFields = [ |
|
42
|
|
|
[ |
|
43
|
|
|
'description', |
|
44
|
|
|
Type\TextType::class, |
|
45
|
|
|
[ |
|
46
|
|
|
FormTypeLabelInterface::LABEL => 'Description', |
|
47
|
|
|
FormTypeLabelInterface::REQUIRED => true, |
|
48
|
|
|
FormTypeLabelInterface::EMPTY_DATA => '', |
|
49
|
|
|
], |
|
50
|
|
|
], |
|
51
|
|
|
]; |
|
52
|
|
|
|
|
53
|
1 |
|
public function __construct( |
|
54
|
|
|
private readonly UserGroupResource $userGroupResource, |
|
55
|
|
|
private readonly UserGroupTransformer $userGroupTransformer, |
|
56
|
|
|
) { |
|
57
|
1 |
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* {@inheritdoc} |
|
61
|
|
|
* |
|
62
|
|
|
* @throws Throwable |
|
63
|
|
|
*/ |
|
64
|
1 |
|
public function buildForm(FormBuilderInterface $builder, array $options): void |
|
65
|
|
|
{ |
|
66
|
1 |
|
parent::buildForm($builder, $options); |
|
67
|
|
|
|
|
68
|
1 |
|
$this->addBasicFieldToForm($builder, self::$formFields); |
|
69
|
|
|
|
|
70
|
1 |
|
$builder |
|
71
|
1 |
|
->add( |
|
72
|
1 |
|
'userGroups', |
|
73
|
1 |
|
Type\ChoiceType::class, |
|
74
|
1 |
|
[ |
|
75
|
1 |
|
'choices' => $this->getUserGroupChoices(), |
|
76
|
1 |
|
'multiple' => true, |
|
77
|
1 |
|
'required' => true, |
|
78
|
1 |
|
'empty_data' => '', |
|
79
|
1 |
|
], |
|
80
|
1 |
|
); |
|
81
|
|
|
|
|
82
|
1 |
|
$builder->get('userGroups')->addModelTransformer($this->userGroupTransformer); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
1 |
|
public function configureOptions(OptionsResolver $resolver): void |
|
86
|
|
|
{ |
|
87
|
1 |
|
parent::configureOptions($resolver); |
|
88
|
|
|
|
|
89
|
1 |
|
$resolver->setDefaults([ |
|
90
|
1 |
|
'data_class' => ApiKey::class, |
|
91
|
1 |
|
]); |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|