1 <?php
declare(strict_types
=1);
4 * This file is part of the Rapsys AirBundle package.
6 * (c) Raphaël Gertz <symfony@rapsys.eu>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Rapsys\AirBundle\Form
;
14 use Symfony\Bridge\Doctrine\Form\Type\EntityType
;
15 use Symfony\Component\Form\Extension\Core\Type\TelType
;
16 use Symfony\Component\Form\Extension\Core\Type\TextType
;
17 use Symfony\Component\Form\FormBuilderInterface
;
18 use Symfony\Component\OptionsResolver\OptionsResolver
;
20 use Rapsys\AirBundle\Entity\Country
;
22 use Rapsys\UserBundle\Form\RegisterType
as BaseRegisterType
;
24 class RegisterType
extends BaseRegisterType
{
28 public function buildForm(FormBuilderInterface
$builder, array $options): FormBuilderInterface
{
29 //Call parent build form
30 $form = parent
::buildForm($builder, $options);
32 //Add extra city field
33 if (!empty($options['city'])) {
34 $form->add('city', TextType
::class, ['attr' => ['placeholder' => 'Your city'], 'required' => false]);
37 //Add extra country field
38 if (!empty($options['country'])) {
40 $form->add('country', EntityType
::class, ['class' => $options['country_class'], 'choice_label' => 'title'/*, 'choices' => $options['location_choices']*/, 'preferred_choices' => $options['country_favorites'], 'attr' => ['placeholder' => 'Your country'], 'choice_translation_domain' => false, 'required' => true, 'data' => $options['country_default']]);
43 //Add extra phone field
44 if (!empty($options['phone'])) {
45 $form->add('phone', TelType
::class, ['attr' => ['placeholder' => 'Your phone'], 'required' => false]);
48 //Add extra pseudonym field
49 if (!empty($options['pseudonym'])) {
50 $form->add('pseudonym', TextType
::class, ['attr' => ['placeholder' => 'Your pseudonym'], 'required' => false]);
53 //Add extra zipcode field
54 if (!empty($options['zipcode'])) {
55 $form->add('zipcode', TextType
::class, ['attr' => ['placeholder' => 'Your zipcode'], 'required' => false]);
65 public function configureOptions(OptionsResolver
$resolver): void {
66 //Call parent configure options
67 parent
::configureOptions($resolver);
70 $resolver->setDefaults(['city' => true, 'country' => true, 'country_class' => 'Rapsys\AirBundle\Entity\Country', 'country_default' => null, 'country_favorites' => [], 'phone' => true, 'pseudonym' => true, 'zipcode' => true]);
72 //Add extra city option
73 $resolver->setAllowedTypes('city', 'boolean');
75 //Add extra country option
76 $resolver->setAllowedTypes('country', 'boolean');
79 $resolver->setAllowedTypes('country_class', 'string');
82 $resolver->setAllowedTypes('country_default', [Country
::class, 'null']);
84 //Add country favorites
85 $resolver->setAllowedTypes('country_favorites', 'array');
87 //Add extra phone option
88 $resolver->setAllowedTypes('phone', 'boolean');
90 //Add extra pseudonym option
91 $resolver->setAllowedTypes('pseudonym', 'boolean');
93 //Add extra zipcode option
94 $resolver->setAllowedTypes('zipcode', 'boolean');
101 public function getName(): string {
102 return 'rapsys_air_register';