Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 30 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
MovieType | |
0.00% |
0 / 30 |
|
0.00% |
0 / 2 |
6 | |
0.00% |
0 / 1 |
buildForm | |
0.00% |
0 / 27 |
|
0.00% |
0 / 1 |
2 | |||
configureOptions | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace App\Form; |
4 | |
5 | use App\Entity\Genre; |
6 | use App\Entity\Movie; |
7 | use App\Entity\Type; |
8 | use Symfony\Bridge\Doctrine\Form\Type\EntityType; |
9 | use Symfony\Component\Form\AbstractType; |
10 | use Symfony\Component\Form\FormBuilderInterface; |
11 | use Symfony\Component\OptionsResolver\OptionsResolver; |
12 | |
13 | class MovieType extends AbstractType |
14 | { |
15 | public function buildForm(FormBuilderInterface $builder, array $options): void |
16 | { |
17 | $builder |
18 | ->add('title') |
19 | ->add('duration') |
20 | ->add('rating') |
21 | ->add('summary') |
22 | ->add('synopsis') |
23 | ->add('releaseDate') |
24 | ->add('country') |
25 | ->add('poster') |
26 | // j'ai une relation avec une autre Entité |
27 | // l'élément HTML désiré : Choix : ChoiceType |
28 | // on veux un choiceType spécialisé pour les entités : EntityType |
29 | // ? https://symfony.com/doc/5.4/reference/forms/types/entity.html |
30 | ->add('type', EntityType::class, [ |
31 | // * c'est un ChoiceType : multiple + expanded |
32 | "multiple" => false, |
33 | "expanded" => false, // radiobutton |
34 | // ! The required option "class" is missing. |
35 | // ? à quelle entité est on lié ? |
36 | "class" => Type::class, |
37 | // ! Object of class Proxies\__CG__\App\Entity\Type could not be converted to string |
38 | // on doit préciser la propriété pour l'affichage |
39 | 'choice_label' => 'name', |
40 | |
41 | ]) |
42 | ->add('genres', EntityType::class, [ |
43 | // * c'est un ChoiceType : multiple + expanded |
44 | // ! Genres c'est un tableau : multiple = true |
45 | "multiple" => true, |
46 | "expanded" => true, // checkbox |
47 | // * EntityType : class est obligatoire |
48 | "class" => Genre::class, |
49 | // * EntityType : choice_label est obligatoire |
50 | 'choice_label' => 'name', |
51 | ] |
52 | ) |
53 | ; |
54 | } |
55 | |
56 | public function configureOptions(OptionsResolver $resolver): void |
57 | { |
58 | $resolver->setDefaults([ |
59 | 'data_class' => Movie::class, |
60 | ]); |
61 | } |
62 | } |