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