<?php
namespace App\Form\GuardianShortRegister;
use App\Entity\GuardianRegister\GuardianRegister;
use App\Utils\HelperUtils;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TelType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class GuardianShortRegisterContactStepType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
/** @var GuardianRegister $guardianRegister */
$guardianRegister = $options['data'];
$phoneNumber = $guardianRegister->getPhone();
$countryChoices = [];
$countryChoicesAttr = [];
$countryData = HelperUtils::countryData(1);
$countryCode = 'LT';
foreach ($countryData as $countryDatum)
{
$countryChoices["{$countryDatum['country']}"] = "{$countryDatum['code']}";
$countryChoicesAttr["{$countryDatum['country']}"] = [
'data-dialcode' => "{$countryDatum['dialCode']}",
'data-digits' => "{$countryDatum['digits']}",
'data-size' => "{$countryDatum['size']}",
'data-minsize' => "{$countryDatum['minsize']}",
'data-code' => "{$countryDatum['code']}",
// 'data-flag' => "{$countryDatum['flag']}",
'data-flag' => base64_encode($countryDatum['flag_raw']),
// 'data-flag' => json_encode(urlencode($countryDatum['flag'])),
];
$phoneNumber = str_replace($countryDatum['dialCode'], '', $phoneNumber);
// break;
}
$emailRequired = true;
if($options['type'] == 'mokiniams') {
$emailRequired = false;
}
$builder
->add('email', EmailType::class, [
'label' => false,
'required' => $emailRequired,
'attr' => ['placeholder' => 'El. paštas']
])
->add('country', ChoiceType::class, [
'label' => false,
'required' => true,
'choices' => $countryChoices,
'choice_attr' => $countryChoicesAttr,
'attr' => ['data-country' => $countryCode],
'row_attr' => ['class' => 'half'],
'data'=>'LT',
'mapped' => false
])
->add('phone', TelType::class, [
'label' => false,
'required' => true,
'attr' => ['placeholder' => '0000 0000'],
'row_attr' => ['class' => 'half'],
'data' => $phoneNumber
])
->add('referralCode', TextType::class, [
'label' => 'Nuolaidos kodas',
'attr' => ['placeholder' => 'Nuolaidos kodas'],
'required' => false,
]);
if($options['type'] == 'mokiniams') {
$builder->add('class', ChoiceType::class, [
'placeholder' => 'Pasirinkite klasę',
'label' => 'Klasė',
'required' => true,
'choices' => [
"<1" => 0,
1 => 1,
2 => 2,
3 => 3,
4 => 4,
5 => 5,
6 => 6,
7 => 7,
8 => 8,
9 => 9,
10 => 10,
11 => 11,
12 => 12,
">12" => 13,
],
'multiple' => false,
'mapped' => false,
]);
}
$builder
->add('consent', CheckboxType::class, [
'label_html' => true,
'mapped' => false,
'row_attr' => ['class' => 'consent-div'],
'label' => 'Sutinku su MB „Corepetitus“ <a href="https://app.corepetitus.lt/privacy-policy">Privatumo politika</a> bei gauti naujienas ir pasiūlymus.',
]);
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => GuardianRegister::class,
'type' => null,
]);
}
}