]> Raphaël G. Git Repositories - airbundle/blob - Form/RegisterType.php
68c9309a0e4f72ad97c2df28755bea2ff5766909
[airbundle] / Form / RegisterType.php
1 <?php declare(strict_types=1);
2
3 /*
4 * This file is part of the Rapsys PackBundle 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\Extension\Core\Type\UrlType;
17 use Symfony\Component\Form\FormBuilderInterface;
18 use Symfony\Component\OptionsResolver\OptionsResolver;
19 use Symfony\Component\Validator\Constraints\NotBlank;
20
21 class RegisterType extends \Rapsys\UserBundle\Form\RegisterType {
22 /**
23 * {@inheritdoc}
24 */
25 public function buildForm(FormBuilderInterface $builder, array $options): FormBuilderInterface {
26 //Call parent build form
27 $form = parent::buildForm($builder, $options);
28
29 //Add extra donate field
30 if (!empty($options['donate'])) {
31 $form->add('donate', UrlType::class, ['attr' => ['placeholder' => 'Your donate'], 'required' => false]);
32 }
33
34 //Add extra link field
35 if (!empty($options['link'])) {
36 $form->add('link', UrlType::class, ['attr' => ['placeholder' => 'Your link'], 'required' => false]);
37 }
38
39 //Add extra phone field
40 if (!empty($options['phone'])) {
41 $form->add('phone', TelType::class, ['attr' => ['placeholder' => 'Your phone'], 'required' => false]);
42 }
43
44 //Add extra profile field
45 if (!empty($options['profile'])) {
46 $form->add('profile', UrlType::class, ['attr' => ['placeholder' => 'Your profile'], 'required' => false]);
47 }
48
49 //Return form
50 return $form;
51 }
52
53 /**
54 * {@inheritdoc}
55 */
56 public function configureOptions(OptionsResolver $resolver): void {
57 //Call parent configure options
58 parent::configureOptions($resolver);
59
60 //Set defaults
61 $resolver->setDefaults(['donate' => true, 'link' => true, 'phone' => true, 'profile' => true]);
62
63 //Add extra donate option
64 $resolver->setAllowedTypes('donate', 'boolean');
65
66 //Add extra link option
67 $resolver->setAllowedTypes('link', 'boolean');
68
69 //Add extra phone option
70 $resolver->setAllowedTypes('phone', 'boolean');
71
72 //Add extra profile option
73 $resolver->setAllowedTypes('profile', 'boolean');
74 }
75
76
77 /**
78 * {@inheritdoc}
79 */
80 public function getName(): string {
81 return 'rapsys_air_register';
82 }
83 }