Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
29 / 29 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
CastingType | |
100.00% |
29 / 29 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
buildForm | |
100.00% |
26 / 26 |
|
100.00% |
1 / 1 |
1 | |||
configureOptions | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace App\Form; |
4 | |
5 | use App\Entity\Casting; |
6 | use App\Entity\Movie; |
7 | use App\Entity\Person; |
8 | use Doctrine\ORM\EntityRepository; |
9 | use Symfony\Bridge\Doctrine\Form\Type\EntityType; |
10 | use Symfony\Component\Form\AbstractType; |
11 | use Symfony\Component\Form\FormBuilderInterface; |
12 | use Symfony\Component\OptionsResolver\OptionsResolver; |
13 | |
14 | class CastingType extends AbstractType |
15 | { |
16 | public function buildForm(FormBuilderInterface $builder, array $options): void |
17 | { |
18 | $builder |
19 | ->add('role') |
20 | ->add('creditOrder') |
21 | ->add('person', EntityType::class, [ |
22 | "multiple" => false, |
23 | "expanded" => false, // dropdown |
24 | "class" => Person::class, |
25 | // TODO : on veu le prénom + nom |
26 | // 1ere solution faire une function anonyme QUE pour le formulaire |
27 | // l'argument $entity sera chaque instance des objets de la relation |
28 | "choice_label" => function ($entity) |
29 | { |
30 | /** @var Person $entity */ |
31 | return $entity->getFirstname() . " " . $entity->getLastname(); |
32 | } |
33 | |
34 | // 2eme solution, créer une function dans notre entité |
35 | // et l'utiliser comme propriété ici |
36 | // "choice_label" => "fullname" |
37 | |
38 | ]) |
39 | ->add('movie', EntityType::class, [ |
40 | "multiple" => false, |
41 | "expanded" => false, // dropdown |
42 | "class" => Movie::class, |
43 | "choice_label" => "title", |
44 | // ? https://symfony.com/doc/5.4/reference/forms/types/entity.html#query-builder |
45 | "query_builder" => function(EntityRepository $entityrepository){ |
46 | // TODO : requete perso : tri par titre |
47 | return $entityrepository->createQueryBuilder('m') |
48 | ->orderBy('m.title', 'ASC'); |
49 | } |
50 | ]) |
51 | ; |
52 | } |
53 | |
54 | public function configureOptions(OptionsResolver $resolver): void |
55 | { |
56 | $resolver->setDefaults([ |
57 | 'data_class' => Casting::class, |
58 | ]); |
59 | } |
60 | } |