Lines
100.00%
16 / 16
Functions and Methods
100.00%
2 / 2
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| UserType | 100.00% | 16 / 16 | 100.00% | 2 / 2 | 2 | 100.00% | 1 / 1 | |||
| buildForm | 100.00% | 13 / 13 | 100.00% | 1 / 1 | 1 | |||||
| configureOptions | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 1 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace App\Form; | |
| 6 | ||
| 7 | use App\Entity\User; | |
| 8 | use App\Enum\UserRole; | |
| 9 | use Symfony\Component\Form\AbstractType; | |
| 10 | use Symfony\Component\Form\Extension\Core\Type\EnumType; | |
| 11 | use Symfony\Component\Form\FormBuilderInterface; | |
| 12 | use Symfony\Component\OptionsResolver\OptionsResolver; | |
| 13 | ||
| 14 | class UserType extends AbstractType | |
| 15 | { | |
| 16 | public function buildForm(FormBuilderInterface $builder, array $options): void | |
| 17 | { | |
| 18 | $builder | |
| 19 | ->add('identifier', null, ['label' => 'user.identifier']) | |
| 20 | ->add('role', EnumType::class, [ | |
| 21 | 'class' => UserRole::class, | |
| 22 | 'label' => 'user.role', | |
| 23 | 'choice_label' => fn (UserRole $role) => $role->label(), | |
| 24 | ]) | |
| 25 | ->add('agentName', null, [ | |
| 26 | 'required' => false, | |
| 27 | 'label' => 'user.agent_name', | |
| 28 | 'help' => 'user.agent_name_help', | |
| 29 | ]) | |
| 30 | ; | |
| 31 | } | |
| 32 | ||
| 33 | public function configureOptions(OptionsResolver $resolver): void | |
| 34 | { | |
| 35 | $resolver->setDefaults([ | |
| 36 | 'data_class' => User::class, | |
| 37 | ]); | |
| 38 | } | |
| 39 | } |