]> Raphaël G. Git Repositories - blogbundle/blob - Form/EditType.php
New structure
[blogbundle] / Form / EditType.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\BlogBundle\Form;
13
14 use Symfony\Component\Form\Extension\Core\Type\TextType;
15 use Symfony\Component\Form\FormBuilderInterface;
16 use Symfony\Component\OptionsResolver\OptionsResolver;
17
18 use Rapsys\UserBundle\Form\EditType as BaseEditType;
19
20 class EditType extends BaseEditType {
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 pseudonym field
29 if (!empty($options['pseudonym'])) {
30 $form->add('pseudonym', TextType::class, ['attr' => ['placeholder' => 'Your pseudonym'], 'required' => false]);
31 }
32
33 //Add extra slug field
34 if (!empty($options['slug'])) {
35 $form->add('slug', TextType::class, ['attr' => ['placeholder' => 'Your slug'], 'required' => false]);
36 }
37
38 //Return form
39 return $form;
40 }
41
42 /**
43 * {@inheritdoc}
44 */
45 public function configureOptions(OptionsResolver $resolver): void {
46 //Call parent configure options
47 parent::configureOptions($resolver);
48
49 //Set defaults
50 $resolver->setDefaults(['pseudonym' => true, 'slug' => false]);
51
52 //Add extra pseudonym option
53 $resolver->setAllowedTypes('pseudonym', 'boolean');
54
55 //Add extra slug option
56 $resolver->setAllowedTypes('slug', 'boolean');
57 }
58
59 /**
60 * {@inheritdoc}
61 */
62 public function getName(): string {
63 return 'rapsys_blog_edit';
64 }
65 }