Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
56 / 56 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| ReviewType | |
100.00% |
56 / 56 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| buildForm | |
100.00% |
52 / 52 |
|
100.00% |
1 / 1 |
1 | |||
| configureOptions | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Form; |
| 4 | |
| 5 | use App\Entity\Review; |
| 6 | use Symfony\Component\Form\AbstractType; |
| 7 | use Symfony\Component\Form\Extension\Core\Type\ChoiceType; |
| 8 | use Symfony\Component\Form\Extension\Core\Type\DateType; |
| 9 | use Symfony\Component\Form\Extension\Core\Type\EmailType; |
| 10 | use Symfony\Component\Form\Extension\Core\Type\NumberType; |
| 11 | use Symfony\Component\Form\Extension\Core\Type\TextareaType; |
| 12 | use Symfony\Component\Form\Extension\Core\Type\TextType; |
| 13 | use Symfony\Component\Form\FormBuilderInterface; |
| 14 | use Symfony\Component\OptionsResolver\OptionsResolver; |
| 15 | |
| 16 | class ReviewType extends AbstractType |
| 17 | { |
| 18 | public function buildForm(FormBuilderInterface $builder, array $options): void |
| 19 | { |
| 20 | $builder |
| 21 | // ? https://symfony.com/doc/5.4/reference/forms/types/text.html |
| 22 | ->add('username', TextType::class, [ |
| 23 | "label" => "Votre pseudo:", |
| 24 | "attr" => [ |
| 25 | "placeholder" => "votre pseudo ..." |
| 26 | ] |
| 27 | ]) |
| 28 | // ? https://symfony.com/doc/5.4/reference/forms/types/email.html |
| 29 | ->add('email', EmailType::class, [ |
| 30 | "label" => "Votre E-mail:", |
| 31 | "attr" => [ |
| 32 | "placeholder" => "aloha@hawaï.com" |
| 33 | ] |
| 34 | ]) |
| 35 | ->add('content', TextareaType::class, [ |
| 36 | "label" => "Votre commentaire : ", |
| 37 | "attr" => [ |
| 38 | "placeholder" => "Il était bien ce film ..." |
| 39 | ] |
| 40 | ]) |
| 41 | // ? https://symfony.com/doc/5.4/reference/forms/types/choice.html |
| 42 | ->add('rating', ChoiceType::class, [ |
| 43 | // la liste fermée de choix |
| 44 | 'choices' => [ |
| 45 | 'Excellent' => 5, |
| 46 | "Très bon" => 4, |
| 47 | "Bon" => 3, |
| 48 | "Peut mieux faire" => 2, |
| 49 | "A éviter" => 1 |
| 50 | ], |
| 51 | // * si on utilise le choiceType (ou ses enfants) toujours ajouter : |
| 52 | // multiple + expanded |
| 53 | "multiple" => false, |
| 54 | "expanded" => true, |
| 55 | ]) |
| 56 | ->add('reactions', ChoiceType::class, [ |
| 57 | // * si on utilise le choiceType (ou ses enfants) toujours ajouter : |
| 58 | // multiple + expanded |
| 59 | // ! Notice: Array to string conversion |
| 60 | // si on ne met pas multiple à true, il va y avoir conflit avec le type de donnée de la propriétés |
| 61 | // tableau ==> multiple=true |
| 62 | "multiple" => true, |
| 63 | "expanded" => true, |
| 64 | 'choices' => [ |
| 65 | // smile, cry, think, sleep, dream |
| 66 | // Rire 😂, Pleurer 😭, Réfléchir 🤔, Dormir 😴, Rêver 💭 |
| 67 | 'Rire 😂' => "smile", |
| 68 | "Pleurer 😭" => "cry", |
| 69 | "Réfléchir 🤔" => "think", |
| 70 | "Dormir 😴" => "sleep", |
| 71 | "Rêver 💭" => "dream" |
| 72 | ], |
| 73 | ]) |
| 74 | // ? https://symfony.com/doc/5.4/reference/forms/types/date.html |
| 75 | ->add('watchedAt', DateType::class, [ |
| 76 | //? https://symfony.com/doc/5.4/reference/forms/types/date.html#widget |
| 77 | "widget" => "single_text", |
| 78 | // ? https://symfony.com/doc/5.4/reference/forms/types/date.html#input |
| 79 | "input" => "datetime_immutable" |
| 80 | ]) |
| 81 | // ! Object of class App\Entity\Movie could not be converted to string |
| 82 | // ->add('movie') |
| 83 | ; |
| 84 | } |
| 85 | |
| 86 | public function configureOptions(OptionsResolver $resolver): void |
| 87 | { |
| 88 | $resolver->setDefaults([ |
| 89 | 'data_class' => Review::class, |
| 90 | // ça fait doublon avec la version dans twig |
| 91 | // ici c'est plus général |
| 92 | // on définit les attributs de la balise <form> |
| 93 | "attr" => ["novalidate" => 'novalidate', "class" => "my-css-class"] |
| 94 | ]); |
| 95 | } |
| 96 | } |