From: Raphaƫl Gertz Date: Thu, 3 Dec 2026 02:59:45 +0000 (+0100) Subject: Fix buildForm to match upstream prototype and return value X-Git-Tag: 0.6.0~5 X-Git-Url: https://git.rapsys.eu/airbundle/commitdiff_plain/1be898ed564b18e6ac635d4d605efd7a388991b3 Fix buildForm to match upstream prototype and return value Fix NotBlank, Email and File constraint new constructor prototype --- diff --git a/Form/ApplicationType.php b/Form/ApplicationType.php index f52ad8c..6c6397d 100644 --- a/Form/ApplicationType.php +++ b/Form/ApplicationType.php @@ -34,21 +34,21 @@ class ApplicationType extends AbstractType { */ public function buildForm(FormBuilderInterface $builder, array $options): void { //Add dance field - $builder->add('dance', EntityType::class, ['class' => 'Rapsys\AirBundle\Entity\Dance', 'choices' => $options['dance_choices'], 'preferred_choices' => $options['dance_favorites'], 'attr' => ['placeholder' => 'Your dance'], 'choice_translation_domain' => true, 'constraints' => [new NotBlank(['message' => 'Please provide your dance'])], 'data' => $options['dance_default']]); + $builder->add('dance', EntityType::class, ['class' => 'Rapsys\AirBundle\Entity\Dance', 'choices' => $options['dance_choices'], 'preferred_choices' => $options['dance_favorites'], 'attr' => ['placeholder' => 'Your dance'], 'choice_translation_domain' => true, 'constraints' => [new NotBlank(null, 'Please provide your dance')], 'data' => $options['dance_default']]); //Add date field - $builder->add('date', DateType::class, ['attr' => ['placeholder' => 'Your date', 'class' => 'date'], 'html5' => true, 'input' => 'datetime', 'widget' => 'single_text', 'format' => 'yyyy-MM-dd', 'data' => new \DateTime('+7 day'), 'constraints' => [new NotBlank(['message' => 'Please provide your date']), new Type(['type' => \DateTime::class, 'message' => 'Your date doesn\'t seems to be valid'])]]); + $builder->add('date', DateType::class, ['attr' => ['placeholder' => 'Your date', 'class' => 'date'], 'html5' => true, 'input' => 'datetime', 'widget' => 'single_text', 'format' => 'yyyy-MM-dd', 'data' => new \DateTime('+7 day'), 'constraints' => [new NotBlank(null, 'Please provide your date'), new Type(['type' => \DateTime::class, 'message' => 'Your date doesn\'t seems to be valid'])]]); //Add location field - $builder->add('location', EntityType::class, ['class' => 'Rapsys\AirBundle\Entity\Location', 'choices' => $options['location_choices'], 'preferred_choices' => $options['location_favorites'], 'attr' => ['placeholder' => 'Your location'], 'choice_translation_domain' => true, 'constraints' => [new NotBlank(['message' => 'Please provide your location'])], 'data' => $options['location_default']]); + $builder->add('location', EntityType::class, ['class' => 'Rapsys\AirBundle\Entity\Location', 'choices' => $options['location_choices'], 'preferred_choices' => $options['location_favorites'], 'attr' => ['placeholder' => 'Your location'], 'choice_translation_domain' => true, 'constraints' => [new NotBlank(null, 'Please provide your location')], 'data' => $options['location_default']]); //Add slot field - $builder->add('slot', EntityType::class, ['class' => 'Rapsys\AirBundle\Entity\Slot', 'attr' => ['placeholder' => 'Your slot'], 'constraints' => [new NotBlank(['message' => 'Please provide your slot'])], 'choice_translation_domain' => true, 'data' => $options['slot_default']]); + $builder->add('slot', EntityType::class, ['class' => 'Rapsys\AirBundle\Entity\Slot', 'attr' => ['placeholder' => 'Your slot'], 'constraints' => [new NotBlank(null, 'Please provide your slot')], 'choice_translation_domain' => true, 'data' => $options['slot_default']]); //Add extra user field if (!empty($options['user'])) { //XXX: choicetype used here to use our own custom translated string - $builder->add('user', ChoiceType::class, ['attr' => ['placeholder' => 'Your user'], 'choice_translation_domain' => false, 'constraints' => [new NotBlank(['message' => 'Please provide your user'])], 'choices' => $options['user_choices'], 'data' => $options['user_default']]); + $builder->add('user', ChoiceType::class, ['attr' => ['placeholder' => 'Your user'], 'choice_translation_domain' => false, 'constraints' => [new NotBlank(null, 'Please provide your user')], 'choices' => $options['user_choices'], 'data' => $options['user_default']]); } //Add submit diff --git a/Form/ContactType.php b/Form/ContactType.php index 4142c99..2b8dd74 100644 --- a/Form/ContactType.php +++ b/Form/ContactType.php @@ -32,10 +32,10 @@ class ContactType extends CaptchaType { public function buildForm(FormBuilderInterface $builder, array $options): void { //Add fields $builder - ->add('name', TextType::class, ['attr' => ['placeholder' => 'Your name'], 'constraints' => [new NotBlank(['message' => 'Please provide your name'])]]) - ->add('subject', TextType::class, ['attr' => ['placeholder' => 'Subject'], 'constraints' => [new NotBlank(['message' => 'Please provide your subject'])]]) - ->add('mail', EmailType::class, ['attr' => ['placeholder' => 'Your mail'], 'constraints' => [new NotBlank(['message' => 'Please provide a valid mail']), new Email(['message' => 'Your mail doesn\'t seems to be valid'])]]) - ->add('message', TextareaType::class, ['attr' => ['placeholder' => 'Your message', 'cols' => 50, 'rows' => 15], 'constraints' => [new NotBlank(['message' => 'Please provide your message'])]]) + ->add('name', TextType::class, ['attr' => ['placeholder' => 'Your name'], 'constraints' => [new NotBlank(null, 'Please provide your name')]]) + ->add('subject', TextType::class, ['attr' => ['placeholder' => 'Subject'], 'constraints' => [new NotBlank(null, 'Please provide your subject')]]) + ->add('mail', EmailType::class, ['attr' => ['placeholder' => 'Your mail'], 'constraints' => [new NotBlank(null, 'Please provide a valid mail'), new Email(null, 'Your mail doesn\'t seems to be valid')]]) + ->add('message', TextareaType::class, ['attr' => ['placeholder' => 'Your message', 'cols' => 50, 'rows' => 15], 'constraints' => [new NotBlank(null, 'Please provide your message')]]) ->add('submit', SubmitType::class, ['label' => 'Send', 'attr' => ['class' => 'submit']]); //Call parent diff --git a/Form/DisputeType.php b/Form/DisputeType.php index 4bf9285..77dbffa 100644 --- a/Form/DisputeType.php +++ b/Form/DisputeType.php @@ -17,11 +17,11 @@ class DisputeType extends AbstractType { */ public function buildForm(FormBuilderInterface $builder, array $options) { return $builder - ->add('offense', ChoiceType::class, ['choices' => ['Forbidden gathering' => 'gathering', 'Traffic at prohibited time' => 'traffic'/*, 'Traffic at prohibited location' => 'location'*/], 'attr' => ['placeholder' => 'Your offense'], 'constraints' => [new NotBlank(['message' => 'Please provide your offense'])]]) - ->add('court', TextType::class, ['label' => 'Court city', 'attr' => ['placeholder' => 'Your court city'], 'constraints' => [new NotBlank(['message' => 'Please provide your court city'])]]) - ->add('notice', TextType::class, ['label' => 'Notice number', 'attr' => ['placeholder' => 'Your notice number'], 'constraints' => [new NotBlank(['message' => 'Please provide your notice'])]]) - ->add('agent', TextType::class, ['label' => 'Agent number', 'attr' => ['placeholder' => 'Your agent number'], 'constraints' => [new NotBlank(['message' => 'Please provide your agent'])]]) - ->add('service', TextType::class, ['label' => 'Service code', 'attr' => ['placeholder' => 'Your service code'], 'constraints' => [new NotBlank(['message' => 'Please provide your service'])]]) + ->add('offense', ChoiceType::class, ['choices' => ['Forbidden gathering' => 'gathering', 'Traffic at prohibited time' => 'traffic'/*, 'Traffic at prohibited location' => 'location'*/], 'attr' => ['placeholder' => 'Your offense'], 'constraints' => [new NotBlank(null, 'Please provide your offense')]]) + ->add('court', TextType::class, ['label' => 'Court city', 'attr' => ['placeholder' => 'Your court city'], 'constraints' => [new NotBlank(null, 'Please provide your court city')]]) + ->add('notice', TextType::class, ['label' => 'Notice number', 'attr' => ['placeholder' => 'Your notice number'], 'constraints' => [new NotBlank(null, 'Please provide your notice')]]) + ->add('agent', TextType::class, ['label' => 'Agent number', 'attr' => ['placeholder' => 'Your agent number'], 'constraints' => [new NotBlank(null, 'Please provide your agent')]]) + ->add('service', TextType::class, ['label' => 'Service code', 'attr' => ['placeholder' => 'Your service code'], 'constraints' => [new NotBlank(null, 'Please provide your service')]]) ->add('abstract', TextareaType::class, ['attr' => ['placeholder' => 'Your abstract', 'cols' => 50, 'rows' => 15], 'constraints' => []]) ->add('submit', SubmitType::class, ['label' => 'Send', 'attr' => ['class' => 'submit']]); } diff --git a/Form/ImageType.php b/Form/ImageType.php index 300ffe9..612adea 100644 --- a/Form/ImageType.php +++ b/Form/ImageType.php @@ -26,7 +26,7 @@ class ImageType extends AbstractType { /** * {@inheritdoc} */ - public function buildForm(FormBuilderInterface $form, array $options): FormBuilderInterface { + public function buildForm(FormBuilderInterface $form, array $options): void { //With location if ($options['location']) { $form->add('location', HiddenType::class, ['required' => true]); @@ -40,7 +40,7 @@ class ImageType extends AbstractType { //With image if ($options['image']) { //With image - $form->add('image', FileType::class, ['attr' => ['placeholder' => 'Your image'], 'constraints' => [new File(['maxSize' => '5M', 'mimeTypes' => ['image/jpeg', 'image/png', 'image/tiff', 'image/webp'], 'mimeTypesMessage' => 'Please upload a valid Image document'])]/*, 'mapped' => false*/, 'required' => $options['delete'] ? false : true]); + $form->add('image', FileType::class, ['attr' => ['placeholder' => 'Your image'], 'constraints' => [new File(null, '5M', null, ['image/jpeg', 'image/png', 'image/tiff', 'image/webp'], null, null, null, null, 'Please upload a valid Image document')]/*, 'mapped' => false*/, 'required' => $options['delete'] ? false : true]); } //Add submit @@ -52,9 +52,6 @@ class ImageType extends AbstractType { //TODO: add confirm on click ? $form->add('delete', SubmitType::class, ['label' => 'Delete', 'attr' => ['class' => 'submit']]); } - - //Return form builder - return $form; } /** diff --git a/Form/LocationType.php b/Form/LocationType.php index 0072d8b..95b4992 100644 --- a/Form/LocationType.php +++ b/Form/LocationType.php @@ -33,13 +33,13 @@ class LocationType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options): void { //Build form $builder - ->add('title', TextType::class, ['attr' => ['placeholder' => 'Your title'], 'constraints' => [new NotBlank(['message' => 'Please provide your title'])]]) + ->add('title', TextType::class, ['attr' => ['placeholder' => 'Your title'], 'constraints' => [new NotBlank(null, 'Please provide your title')]]) ->add('description', TextareaType::class, ['attr' => ['placeholder' => 'Your description', 'cols' => 50, 'rows' => 15], 'required' => false]) - ->add('address', TextType::class, ['attr' => ['placeholder' => 'Your address'], 'constraints' => [new NotBlank(['message' => 'Please provide your address'])]]) - ->add('zipcode', NumberType::class, ['attr' => ['placeholder' => 'Your zipcode'], 'html5' => true, 'constraints' => [new NotBlank(['message' => 'Please provide your zipcode'])]]) - ->add('city', TextType::class, ['attr' => ['placeholder' => 'Your city'], 'constraints' => [new NotBlank(['message' => 'Please provide your city'])]]) - ->add('latitude', NumberType::class, ['attr' => ['placeholder' => 'Your latitude', 'step' => 0.000001], 'html5' => true, 'scale' => 6, 'constraints' => [new NotBlank(['message' => 'Please provide your latitude'])]]) - ->add('longitude', NumberType::class, ['attr' => ['placeholder' => 'Your longitude', 'step' => 0.000001], 'html5' => true, 'scale' => 6, 'constraints' => [new NotBlank(['message' => 'Please provide your longitude'])]]) + ->add('address', TextType::class, ['attr' => ['placeholder' => 'Your address'], 'constraints' => [new NotBlank(null, 'Please provide your address')]]) + ->add('zipcode', NumberType::class, ['attr' => ['placeholder' => 'Your zipcode'], 'html5' => true, 'constraints' => [new NotBlank(null, 'Please provide your zipcode')]]) + ->add('city', TextType::class, ['attr' => ['placeholder' => 'Your city'], 'constraints' => [new NotBlank(null, 'Please provide your city')]]) + ->add('latitude', NumberType::class, ['attr' => ['placeholder' => 'Your latitude', 'step' => 0.000001], 'html5' => true, 'scale' => 6, 'constraints' => [new NotBlank(null, 'Please provide your latitude')]]) + ->add('longitude', NumberType::class, ['attr' => ['placeholder' => 'Your longitude', 'step' => 0.000001], 'html5' => true, 'scale' => 6, 'constraints' => [new NotBlank(null, 'Please provide your longitude')]]) ->add('indoor', CheckboxType::class, ['attr' => ['placeholder' => 'Your indoor'], 'required' => false]) ->add('hotspot', CheckboxType::class, ['attr' => ['placeholder' => 'Your hotspot'], 'required' => false]) ->add('submit', SubmitType::class, ['label' => 'Send', 'attr' => ['class' => 'submit']]); diff --git a/Form/SessionType.php b/Form/SessionType.php index d6f1ba3..f7c0756 100644 --- a/Form/SessionType.php +++ b/Form/SessionType.php @@ -55,19 +55,19 @@ class SessionType extends AbstractType { if (!empty($options['admin'])) { $builder //Add dance field - ->add('dance', EntityType::class, ['class' => 'Rapsys\AirBundle\Entity\Dance', 'choices' => $options['dance_choices'], 'preferred_choices' => $options['dance_favorites'], 'attr' => ['placeholder' => 'Your dance'], 'choice_translation_domain' => true, 'constraints' => [new NotBlank(['message' => 'Please provide your dance'])], 'data' => $options['dance_default']]) + ->add('dance', EntityType::class, ['class' => 'Rapsys\AirBundle\Entity\Dance', 'choices' => $options['dance_choices'], 'preferred_choices' => $options['dance_favorites'], 'attr' => ['placeholder' => 'Your dance'], 'choice_translation_domain' => true, 'constraints' => [new NotBlank(null, 'Please provide your dance')], 'data' => $options['dance_default']]) //Add slot field - ->add('slot', EntityType::class, ['class' => 'Rapsys\AirBundle\Entity\Slot', 'attr' => ['placeholder' => 'Your slot'], 'constraints' => [new NotBlank(['message' => 'Please provide your slot'])], 'choice_translation_domain' => true, 'data' => $options['slot_default']]) + ->add('slot', EntityType::class, ['class' => 'Rapsys\AirBundle\Entity\Slot', 'attr' => ['placeholder' => 'Your slot'], 'constraints' => [new NotBlank(null, 'Please provide your slot')], 'choice_translation_domain' => true, 'data' => $options['slot_default']]) //Add date field - ->add('date', DateType::class, ['attr' => ['placeholder' => 'Your date', 'class' => 'date'], 'html5' => true, 'input' => 'datetime', 'widget' => 'single_text', 'format' => 'yyyy-MM-dd', 'data' => $options['date'], 'constraints' => [new NotBlank(['message' => 'Please provide your date']), new Type(['type' => \DateTime::class, 'message' => 'Your date doesn\'t seems to be valid'])]]); + ->add('date', DateType::class, ['attr' => ['placeholder' => 'Your date', 'class' => 'date'], 'html5' => true, 'input' => 'datetime', 'widget' => 'single_text', 'format' => 'yyyy-MM-dd', 'data' => $options['date'], 'constraints' => [new NotBlank(null, 'Please provide your date'), new Type(['type' => \DateTime::class, 'message' => 'Your date doesn\'t seems to be valid'])]]); } $builder //TODO: avertissement + minimum et maximum ??? - ->add('begin', TimeType::class, ['attr' => ['placeholder' => 'Your begin', 'class' => 'time'], 'html5' => true, 'input' => 'datetime', 'widget' => 'single_text', 'data' => $options['begin'], 'constraints' => [new NotBlank(['message' => 'Please provide your begin']), new Type(['type' => \DateTime::class, 'message' => 'Your begin doesn\'t seems to be valid'])]]) + ->add('begin', TimeType::class, ['attr' => ['placeholder' => 'Your begin', 'class' => 'time'], 'html5' => true, 'input' => 'datetime', 'widget' => 'single_text', 'data' => $options['begin'], 'constraints' => [new NotBlank(null, 'Please provide your begin'), new Type(['type' => \DateTime::class, 'message' => 'Your begin doesn\'t seems to be valid'])]]) //TODO: avertissement + minimum et maximum ??? - ->add('length', TimeType::class, ['attr' => ['placeholder' => 'Your length', 'class' => 'time'], 'html5' => true, 'input' => 'datetime', 'widget' => 'single_text', 'data' => $options['length'], 'constraints' => [new NotBlank(['message' => 'Please provide your length']), new Type(['type' => \DateTime::class, 'message' => 'Your length doesn\'t seems to be valid'])]]) + ->add('length', TimeType::class, ['attr' => ['placeholder' => 'Your length', 'class' => 'time'], 'html5' => true, 'input' => 'datetime', 'widget' => 'single_text', 'data' => $options['length'], 'constraints' => [new NotBlank(null, 'Please provide your length'), new Type(['type' => \DateTime::class, 'message' => 'Your length doesn\'t seems to be valid'])]]) ->add('modify', SubmitType::class, ['label' => 'Modify', 'attr' => ['class' => 'submit']]); } @@ -82,7 +82,7 @@ class SessionType extends AbstractType { $locations = $this->doctrine->getRepository(Location::class)->findComplementBySessionId($options['session']); $builder //TODO: class senior en orange ??? - ->add('location', ChoiceType::class, ['attr' => ['placeholder' => 'Your location'], 'constraints' => [new NotBlank(['message' => 'Please provide your location'])], 'choices' => $locations, 'choice_translation_domain' => true]) + ->add('location', ChoiceType::class, ['attr' => ['placeholder' => 'Your location'], 'constraints' => [new NotBlank(null, 'Please provide your location')], 'choices' => $locations, 'choice_translation_domain' => true]) ->add('move', SubmitType::class, ['label' => 'Move', 'attr' => ['class' => 'submit']]); } @@ -93,7 +93,7 @@ class SessionType extends AbstractType { //Add admin fields $builder //TODO: class admin en rouge ??? - ->add('user', ChoiceType::class, ['attr' => ['placeholder' => 'Your user'], 'constraints' => [new NotBlank(['message' => 'Please provide your user'])], 'choices' => $users, 'data' => $options['user'], 'choice_translation_domain' => false]) + ->add('user', ChoiceType::class, ['attr' => ['placeholder' => 'Your user'], 'constraints' => [new NotBlank(null, 'Please provide your user')], 'choices' => $users, 'data' => $options['user'], 'choice_translation_domain' => false]) ->add('lock', SubmitType::class, ['label' => 'Lock', 'attr' => ['class' => 'submit']]); //Is admin and locked === null diff --git a/Form/SnippetType.php b/Form/SnippetType.php index 8f81b40..004499a 100644 --- a/Form/SnippetType.php +++ b/Form/SnippetType.php @@ -21,7 +21,7 @@ class SnippetType extends AbstractType { /** * {@inheritdoc} */ - public function buildForm(FormBuilderInterface $form, array $options): FormBuilderInterface { + public function buildForm(FormBuilderInterface $form, array $options): void { //Start build form $form //Add locale, location and user hidden fields @@ -76,9 +76,6 @@ class SnippetType extends AbstractType { //Add submit $form->add('submit', SubmitType::class, ['label' => 'Send', 'attr' => ['class' => 'submit']]); - - //Return form builder - return $form; } /**