Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
27 / 27 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| MediaType | |
100.00% |
27 / 27 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| buildForm | |
100.00% |
23 / 23 |
|
100.00% |
1 / 1 |
2 | |||
| configureOptions | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Form; |
| 4 | |
| 5 | use App\Entity\Album; |
| 6 | use App\Entity\Media; |
| 7 | use App\Entity\User; |
| 8 | use Symfony\Bridge\Doctrine\Form\Type\EntityType; |
| 9 | use Symfony\Component\Form\AbstractType; |
| 10 | use Symfony\Component\Form\Extension\Core\Type\FileType; |
| 11 | use Symfony\Component\Form\Extension\Core\Type\TextType; |
| 12 | use Symfony\Component\Form\FormBuilderInterface; |
| 13 | use Symfony\Component\OptionsResolver\OptionsResolver; |
| 14 | |
| 15 | /** |
| 16 | * @extends AbstractType<Media> |
| 17 | */ |
| 18 | class MediaType extends AbstractType |
| 19 | { |
| 20 | public function buildForm(FormBuilderInterface $builder, array $options): void |
| 21 | { |
| 22 | $builder |
| 23 | ->add('file', FileType::class, [ |
| 24 | 'label' => 'Image', |
| 25 | ]) |
| 26 | ->add('title', TextType::class, [ |
| 27 | 'label' => 'Titre', |
| 28 | ]) |
| 29 | ; |
| 30 | |
| 31 | if ($options['is_super_admin']) { |
| 32 | $builder |
| 33 | ->add('user', EntityType::class, [ |
| 34 | 'label' => 'Utilisateur', |
| 35 | 'required' => false, |
| 36 | 'class' => User::class, |
| 37 | 'choice_label' => 'name', |
| 38 | ]) |
| 39 | ->add('album', EntityType::class, [ |
| 40 | 'label' => 'Album', |
| 41 | 'required' => false, |
| 42 | 'class' => Album::class, |
| 43 | 'choice_label' => 'name', |
| 44 | ]) |
| 45 | ; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | public function configureOptions(OptionsResolver $resolver): void |
| 50 | { |
| 51 | $resolver->setDefaults([ |
| 52 | 'data_class' => Media::class, |
| 53 | 'is_super_admin' => false, |
| 54 | ]); |
| 55 | } |
| 56 | } |