src/Form/MainFormType.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use Doctrine\DBAL\Types\TextType;
  4. use Symfony\Component\Form\AbstractType;
  5. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  6. use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  7. use Symfony\Component\Form\Extension\Core\Type\DateType;
  8. use Symfony\Component\Form\Extension\Core\Type\RadioType;
  9. use Symfony\Component\Form\FormBuilderInterface;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\OptionsResolver\OptionsResolver;
  13. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  14. class MainFormType extends AbstractType
  15. {
  16.     public function getDefaultOptions(array $options)
  17.     {
  18.         return array(
  19.             'csrf_protection' => false,
  20.             // Rest of options omitted
  21.         );
  22.     }
  23.     public function buildForm(FormBuilderInterface $builder, array $options): void
  24.     {
  25.         $datas $options['data'];
  26.         $local $datas['local'];
  27.         $continuBtnText null;
  28.         $firstCustomAwnser null;
  29.         $secondCustomAwnser null;
  30.         $thirdCustomAwnser null;
  31.         if ($local) {
  32.             switch ($local) {
  33.                 case 'fr':
  34.                     $continuBtnText "Continuer";
  35.                     break;
  36.                 case 'pt':
  37.                 case 'es':
  38.                 $continuBtnText "Continuar";
  39.                     break;
  40.             }
  41.         }
  42.         if ($datas['selectedQuestion'] != null) {
  43.             $choice1 $datas['selectedQuestion']->getFirstcustomawnser() ?? 'Pas du tout d\'accord';
  44.             $choice2 $datas['selectedQuestion']->getSecondcustomawnser() ?? 'Plutôt d\'accord';
  45.             $choice3 $datas['selectedQuestion']->getThirdcustomawnser() ?? 'Tout à fait d\'accord';
  46.         }
  47.         $builder
  48.             ->add('expertise'ChoiceType::class, [
  49.                 'choices' => [
  50.                     $choice1 => 1,
  51.                     $choice2 => 2,
  52.                     $choice3 => 3
  53.                 ],
  54.                 'expanded' => true,
  55.                 'multiple' => false,
  56.                 'allow_extra_fields' => true,
  57.             ])
  58.             ->add($continuBtnTextSubmitType::class, [
  59.                 'attr' => [
  60.                     'class' => 'form-btn savebtn js-continue-btn',
  61.                     'id' => 'js-continue-btn',
  62.                 ]
  63.             ]);
  64.     }
  65.     public function configureOptions(OptionsResolver $resolver): void
  66.     {
  67.         $resolver->setDefaults([
  68.                  'csrf_protection' => false,
  69.         ]);
  70.     }
  71. }