]> Raphaƫl G. Git Repositories - airbundle/blob - Form/SnippetType.php
Drop organizer controller
[airbundle] / Form / SnippetType.php
1 <?php
2
3 namespace Rapsys\AirBundle\Form;
4
5 use Symfony\Component\Form\AbstractType;
6 use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
7 use Symfony\Component\Form\Extension\Core\Type\FileType;
8 use Symfony\Component\Form\Extension\Core\Type\HiddenType;
9 use Symfony\Component\Form\Extension\Core\Type\NumberType;
10 use Symfony\Component\Form\Extension\Core\Type\SubmitType;
11 use Symfony\Component\Form\Extension\Core\Type\TextareaType;
12 use Symfony\Component\Form\Extension\Core\Type\UrlType;
13 use Symfony\Component\Form\FormBuilderInterface;
14 use Symfony\Component\OptionsResolver\OptionsResolver;
15 use Symfony\Component\Validator\Constraints\File;
16
17 use Rapsys\AirBundle\Form\Extension\Type\HiddenEntityType;
18 use Rapsys\AirBundle\Entity\Snippet;
19
20 class SnippetType extends AbstractType {
21 /**
22 * {@inheritdoc}
23 */
24 public function buildForm(FormBuilderInterface $form, array $options): FormBuilderInterface {
25 //Start build form
26 $form
27 //Add locale, location and user hidden fields
28 ->add('locale', HiddenType::class, ['required' => true])
29 ->add('location', HiddenEntityType::class, ['required' => true])
30 ->add('user', HiddenEntityType::class, ['required' => true]);
31
32 //With description
33 if ($options['description']) {
34 $form->add('description', TextareaType::class, ['attr' => ['placeholder' => 'Your description', 'cols' => 50, 'rows' => 15], 'required' => false]);
35 }
36
37 //With class
38 if ($options['class']) {
39 $form->add('class', TextareaType::class, ['attr' => ['placeholder' => 'Your class', 'cols' => 50, 'rows' => 10], 'required' => false]);
40 }
41
42 //With short
43 if ($options['short']) {
44 $form->add('short', TextareaType::class, ['attr' => ['placeholder' => 'Your short', 'cols' => 50, 'rows' => 10], 'required' => false]);
45 }
46
47 //With rate
48 if ($options['rate']) {
49 $form->add('rate', NumberType::class, ['attr' => ['placeholder' => 'Your rate'], 'required' => false]);
50 }
51
52 //With hat
53 if ($options['hat']) {
54 $form->add('hat', CheckboxType::class, ['attr' => ['placeholder' => 'Your hat'], 'required' => false]);
55 }
56
57 //With contact
58 if ($options['contact']) {
59 $form->add('contact', UrlType::class, ['attr' => ['placeholder' => 'Your contact'], 'required' => false]);
60 }
61
62 //With donate
63 if ($options['donate']) {
64 $form->add('donate', UrlType::class, ['attr' => ['placeholder' => 'Your donate'], 'required' => false]);
65 }
66
67 //With link
68 if ($options['link']) {
69 $form->add('link', UrlType::class, ['attr' => ['placeholder' => 'Your link'], 'required' => false]);
70 }
71
72 //With profile
73 if ($options['profile']) {
74 $form->add('profile', UrlType::class, ['attr' => ['placeholder' => 'Your profile'], 'required' => false]);
75 }
76
77 //Add submit
78 $form->add('submit', SubmitType::class, ['label' => 'Send', 'attr' => ['class' => 'submit']]);
79
80 //Return form builder
81 return $form;
82 }
83
84 /**
85 * {@inheritdoc}
86 */
87 public function configureOptions(OptionsResolver $resolver): void {
88 //Set defaults
89 $resolver->setDefaults(['class' => true, 'contact' => true, 'data_class' => Snippet::class, 'description' => true, 'donate' => true, 'error_bubbling' => true, 'hat' => true, 'link' => true, 'profile' => true, 'rate' => true, 'short' => true]);
90
91 //Add extra class option
92 $resolver->setAllowedTypes('class', 'boolean');
93
94 //Add extra contact option
95 $resolver->setAllowedTypes('contact', 'boolean');
96
97 //Add extra description option
98 $resolver->setAllowedTypes('description', 'boolean');
99
100 //Add extra donate option
101 $resolver->setAllowedTypes('donate', 'boolean');
102
103 //Add extra hat option
104 $resolver->setAllowedTypes('hat', 'boolean');
105
106 //Add extra link option
107 $resolver->setAllowedTypes('link', 'boolean');
108
109 //Add extra profile option
110 $resolver->setAllowedTypes('profile', 'boolean');
111
112 //Add extra rate option
113 $resolver->setAllowedTypes('rate', 'boolean');
114
115 //Add extra short option
116 $resolver->setAllowedTypes('short', 'boolean');
117 }
118
119 /**
120 * {@inheritdoc}
121 */
122 public function getName(): string {
123 return 'rapsys_air_snippet';
124 }
125 }