FilmType.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Film;
  4. use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  5. use Symfony\Component\Form\Extension\Core\Type\TextType;
  6. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  7. use Symfony\Component\Form\AbstractType;
  8. use Symfony\Component\Form\Extension\Core\Type\DateType;
  9. use Symfony\Component\Form\FormBuilderInterface;
  10. use Symfony\Component\OptionsResolver\OptionsResolver;
  11. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  12. class FilmType extends AbstractType
  13. {
  14. /**
  15. * {@inheritdoc}
  16. */
  17. public function buildForm(FormBuilderInterface $builder, array $options): void
  18. {
  19. $builder
  20. ->add('titre', TextType::class)
  21. ->add('annee', DateType::class, array(
  22. 'widget' => 'single_text',
  23. 'label' => 'Année',
  24. 'years' => range(1930, 2050, 1),
  25. 'html5' => false,
  26. 'format' => 'yyyy',
  27. 'required' => false
  28. ))
  29. ->add('lien', TextType::class, array(
  30. 'required' => false
  31. ))
  32. ->add('mediaVideos', CollectionType::class, [
  33. 'entry_type' => MediaVideoType::class,
  34. 'entry_options' => array('label'=>false),
  35. 'allow_add' => true,
  36. 'allow_delete' => true,
  37. 'by_reference' => false
  38. ])
  39. ->add('dateSortie', DateType::class, [
  40. 'input' => 'datetime_immutable',
  41. 'html5' => true,
  42. 'widget' => 'single_text',
  43. 'required' => false
  44. ])
  45. ->add('information', TextareaType::class, [
  46. 'required' => false,
  47. 'attr' => [
  48. 'rows' => 5
  49. ]
  50. ])
  51. ->add('genres', CollectionType::class, [
  52. 'entry_type' => GenreType::class,
  53. 'entry_options' => array('label'=>false),
  54. 'allow_add' => true,
  55. 'allow_delete' => true
  56. ])
  57. ->add('realisateurs', CollectionType::class, [
  58. 'entry_type' => RealisateurType::class,
  59. 'entry_options' => array('label'=>false),
  60. 'allow_add' => true,
  61. 'allow_delete' => true,
  62. 'allow_extra_fields' => true
  63. ])
  64. ->add('save', SubmitType::class, array('label' => 'Enregistrer'));
  65. }
  66. /**
  67. * {@inheritdoc}
  68. */
  69. public function configureOptions(OptionsResolver $resolver): void
  70. {
  71. $resolver->setDefaults([
  72. 'data_class' => Film::class
  73. ]);
  74. }
  75. /**
  76. * {@inheritdoc}
  77. */
  78. public function getBlockPrefix() : string
  79. {
  80. return 'App_film';
  81. }
  82. }