]> Raphaël G. Git Repositories - airbundle/blob - Form/RegisterType.php
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\Component\Form\Extension\Core\Type\TextType;
15 use Symfony\Component\Form\Extension\Core\Type\TelType;
16 use Symfony\Component\Form\FormBuilderInterface;
17 use Symfony\Component\OptionsResolver\OptionsResolver;
18
19 class RegisterType extends \Rapsys\UserBundle\Form\RegisterType {
20 /**
21 * {@inheritdoc}
22 */
23 public function buildForm(FormBuilderInterface $builder, array $options): FormBuilderInterface {
24 //Call parent build form
25 $form = parent::buildForm($builder, $options);
26
27 //Add extra phone field
28 if (!empty($options['phone'])) {
29 $form->add('phone', TelType::class, ['attr' => ['placeholder' => 'Your phone'], 'required' => false]);
30 }
31
32 //Add extra pseudonym field
33 if (!empty($options['pseudonym'])) {
34 $form->add('pseudonym', TextType::class, ['attr' => ['placeholder' => 'Your pseudonym'], 'required' => false]);
35 }
36
37 //Add extra slug field
38 if (!empty($options['slug'])) {
39 $form->add('slug', TextType::class, ['attr' => ['placeholder' => 'Your slug'], 'required' => false]);
40 }
41
42 //Return form
43 return $form;
44 }
45
46 /**
47 * {@inheritdoc}
48 */
49 public function configureOptions(OptionsResolver $resolver): void {
50 //Call parent configure options
51 parent::configureOptions($resolver);
52
53 //Set defaults
54 $resolver->setDefaults(['phone' => true, 'pseudonym' => true, 'slug' => true]);
55
56 //Add extra phone option
57 $resolver->setAllowedTypes('phone', 'boolean');
58
59 //Add extra pseudonym option
60 $resolver->setAllowedTypes('pseudonym', 'boolean');
61
62 //Add extra slug option
63 $resolver->setAllowedTypes('slug', 'boolean');
64 }
65
66
67 /**
68 * {@inheritdoc}
69 */
70 public function getName(): string {
71 return 'rapsys_air_register';
72 }
73 }