src/Form/GuardianShortRegister/GuardianShortRegisterContactStepType.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Form\GuardianShortRegister;
  3. use App\Entity\GuardianRegister\GuardianRegister;
  4. use App\Utils\HelperUtils;
  5. use Symfony\Component\Form\AbstractType;
  6. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  7. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  8. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  9. use Symfony\Component\Form\Extension\Core\Type\TelType;
  10. use Symfony\Component\Form\Extension\Core\Type\TextType;
  11. use Symfony\Component\Form\FormBuilderInterface;
  12. use Symfony\Component\OptionsResolver\OptionsResolver;
  13. class GuardianShortRegisterContactStepType extends AbstractType
  14. {
  15. public function buildForm(FormBuilderInterface $builder, array $options): void
  16. {
  17. /** @var GuardianRegister $guardianRegister */
  18. $guardianRegister = $options['data'];
  19. $phoneNumber = $guardianRegister->getPhone();
  20. $countryChoices = [];
  21. $countryChoicesAttr = [];
  22. $countryData = HelperUtils::countryData(1);
  23. $countryCode = 'LT';
  24. foreach ($countryData as $countryDatum)
  25. {
  26. $countryChoices["{$countryDatum['country']}"] = "{$countryDatum['code']}";
  27. $countryChoicesAttr["{$countryDatum['country']}"] = [
  28. 'data-dialcode' => "{$countryDatum['dialCode']}",
  29. 'data-digits' => "{$countryDatum['digits']}",
  30. 'data-size' => "{$countryDatum['size']}",
  31. 'data-minsize' => "{$countryDatum['minsize']}",
  32. 'data-code' => "{$countryDatum['code']}",
  33. // 'data-flag' => "{$countryDatum['flag']}",
  34. 'data-flag' => base64_encode($countryDatum['flag_raw']),
  35. // 'data-flag' => json_encode(urlencode($countryDatum['flag'])),
  36. ];
  37. $phoneNumber = str_replace($countryDatum['dialCode'], '', $phoneNumber);
  38. // break;
  39. }
  40. $emailRequired = true;
  41. if($options['type'] == 'mokiniams') {
  42. $emailRequired = false;
  43. }
  44. $builder
  45. ->add('email', EmailType::class, [
  46. 'label' => false,
  47. 'required' => $emailRequired,
  48. 'attr' => ['placeholder' => 'El. paštas']
  49. ])
  50. ->add('country', ChoiceType::class, [
  51. 'label' => false,
  52. 'required' => true,
  53. 'choices' => $countryChoices,
  54. 'choice_attr' => $countryChoicesAttr,
  55. 'attr' => ['data-country' => $countryCode],
  56. 'row_attr' => ['class' => 'half'],
  57. 'data'=>'LT',
  58. 'mapped' => false
  59. ])
  60. ->add('phone', TelType::class, [
  61. 'label' => false,
  62. 'required' => true,
  63. 'attr' => ['placeholder' => '0000 0000'],
  64. 'row_attr' => ['class' => 'half'],
  65. 'data' => $phoneNumber
  66. ])
  67. ->add('referralCode', TextType::class, [
  68. 'label' => 'Nuolaidos kodas',
  69. 'attr' => ['placeholder' => 'Nuolaidos kodas'],
  70. 'required' => false,
  71. ]);
  72. if($options['type'] == 'mokiniams') {
  73. $builder->add('class', ChoiceType::class, [
  74. 'placeholder' => 'Pasirinkite klasę',
  75. 'label' => 'Klasė',
  76. 'required' => true,
  77. 'choices' => [
  78. "<1" => 0,
  79. 1 => 1,
  80. 2 => 2,
  81. 3 => 3,
  82. 4 => 4,
  83. 5 => 5,
  84. 6 => 6,
  85. 7 => 7,
  86. 8 => 8,
  87. 9 => 9,
  88. 10 => 10,
  89. 11 => 11,
  90. 12 => 12,
  91. ">12" => 13,
  92. ],
  93. 'multiple' => false,
  94. 'mapped' => false,
  95. ]);
  96. }
  97. $builder
  98. ->add('consent', CheckboxType::class, [
  99. 'label_html' => true,
  100. 'mapped' => false,
  101. 'row_attr' => ['class' => 'consent-div'],
  102. 'label' => 'Sutinku su MB „Corepetitus“ <a href="https://app.corepetitus.lt/privacy-policy">Privatumo politika</a> bei gauti naujienas ir pasiūlymus.',
  103. ]);
  104. }
  105. public function configureOptions(OptionsResolver $resolver): void
  106. {
  107. $resolver->setDefaults([
  108. 'data_class' => GuardianRegister::class,
  109. 'type' => null,
  110. ]);
  111. }
  112. }