]> Raphaël G. Git Repositories - airbundle/blob - Form/RegisterType.php
Add php strict
[airbundle] / Form / RegisterType.php
1 <?php declare(strict_types=1);
2
3 /*
4 * This file is part of the Rapsys AirBundle package.
5 *
6 * (c) Raphaël Gertz <symfony@rapsys.eu>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Rapsys\AirBundle\Form;
13
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;
19
20 use Rapsys\AirBundle\Entity\Country;
21
22 use Rapsys\UserBundle\Form\RegisterType as BaseRegisterType;
23
24 class RegisterType extends BaseRegisterType {
25 /**
26 * {@inheritdoc}
27 */
28 public function buildForm(FormBuilderInterface $builder, array $options): FormBuilderInterface {
29 //Call parent build form
30 $form = parent::buildForm($builder, $options);
31
32 //Add extra city field
33 if (!empty($options['city'])) {
34 $form->add('city', TextType::class, ['attr' => ['placeholder' => 'Your city'], 'required' => false]);
35 }
36
37 //Add extra country field
38 if (!empty($options['country'])) {
39 //Add country field
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']]);
41 }
42
43 //Add extra phone field
44 if (!empty($options['phone'])) {
45 $form->add('phone', TelType::class, ['attr' => ['placeholder' => 'Your phone'], 'required' => false]);
46 }
47
48 //Add extra pseudonym field
49 if (!empty($options['pseudonym'])) {
50 $form->add('pseudonym', TextType::class, ['attr' => ['placeholder' => 'Your pseudonym'], 'required' => false]);
51 }
52
53 //Add extra zipcode field
54 if (!empty($options['zipcode'])) {
55 $form->add('zipcode', TextType::class, ['attr' => ['placeholder' => 'Your zipcode'], 'required' => false]);
56 }
57
58 //Return form
59 return $form;
60 }
61
62 /**
63 * {@inheritdoc}
64 */
65 public function configureOptions(OptionsResolver $resolver): void {
66 //Call parent configure options
67 parent::configureOptions($resolver);
68
69 //Set defaults
70 $resolver->setDefaults(['city' => true, 'country' => true, 'country_class' => 'RapsysAirBundle:Country', 'country_default' => null, 'country_favorites' => [], 'phone' => true, 'pseudonym' => true, 'zipcode' => true]);
71
72 //Add extra city option
73 $resolver->setAllowedTypes('city', 'boolean');
74
75 //Add extra country option
76 $resolver->setAllowedTypes('country', 'boolean');
77
78 //Add country class
79 $resolver->setAllowedTypes('country_class', 'string');
80
81 //Add country default
82 $resolver->setAllowedTypes('country_default', [Country::class, 'null']);
83
84 //Add country favorites
85 $resolver->setAllowedTypes('country_favorites', 'array');
86
87 //Add extra phone option
88 $resolver->setAllowedTypes('phone', 'boolean');
89
90 //Add extra pseudonym option
91 $resolver->setAllowedTypes('pseudonym', 'boolean');
92
93 //Add extra zipcode option
94 $resolver->setAllowedTypes('zipcode', 'boolean');
95 }
96
97
98 /**
99 * {@inheritdoc}
100 */
101 public function getName(): string {
102 return 'rapsys_air_register';
103 }
104 }