3 namespace Rapsys\AirBundle\Form
;
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
;
17 use Rapsys\AirBundle\Form\Extension\Type\HiddenEntityType
;
18 use Rapsys\AirBundle\Entity\Snippet
;
20 class SnippetType
extends AbstractType
{
24 public function buildForm(FormBuilderInterface
$form, array $options): FormBuilderInterface
{
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]);
33 if ($options['description']) {
34 $form->add('description', TextareaType
::class, ['attr' => ['placeholder' => 'Your description', 'cols' => 50, 'rows' => 15], 'required' => false]);
38 if ($options['class']) {
39 $form->add('class', TextareaType
::class, ['attr' => ['placeholder' => 'Your class', 'cols' => 50, 'rows' => 10], 'required' => false]);
43 if ($options['short']) {
44 $form->add('short', TextareaType
::class, ['attr' => ['placeholder' => 'Your short', 'cols' => 50, 'rows' => 10], 'required' => false]);
48 if ($options['rate']) {
49 $form->add('rate', NumberType
::class, ['attr' => ['placeholder' => 'Your rate'], 'required' => false]);
53 if ($options['hat']) {
54 $form->add('hat', CheckboxType
::class, ['attr' => ['placeholder' => 'Your hat'], 'required' => false]);
58 if ($options['contact']) {
59 $form->add('contact', UrlType
::class, ['attr' => ['placeholder' => 'Your contact'], 'required' => false]);
63 if ($options['donate']) {
64 $form->add('donate', UrlType
::class, ['attr' => ['placeholder' => 'Your donate'], 'required' => false]);
68 if ($options['link']) {
69 $form->add('link', UrlType
::class, ['attr' => ['placeholder' => 'Your link'], 'required' => false]);
73 if ($options['profile']) {
74 $form->add('profile', UrlType
::class, ['attr' => ['placeholder' => 'Your profile'], 'required' => false]);
78 $form->add('submit', SubmitType
::class, ['label' => 'Send', 'attr' => ['class' => 'submit']]);
87 public function configureOptions(OptionsResolver
$resolver): void {
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]);
91 //Add extra class option
92 $resolver->setAllowedTypes('class', 'boolean');
94 //Add extra contact option
95 $resolver->setAllowedTypes('contact', 'boolean');
97 //Add extra description option
98 $resolver->setAllowedTypes('description', 'boolean');
100 //Add extra donate option
101 $resolver->setAllowedTypes('donate', 'boolean');
103 //Add extra hat option
104 $resolver->setAllowedTypes('hat', 'boolean');
106 //Add extra link option
107 $resolver->setAllowedTypes('link', 'boolean');
109 //Add extra profile option
110 $resolver->setAllowedTypes('profile', 'boolean');
112 //Add extra rate option
113 $resolver->setAllowedTypes('rate', 'boolean');
115 //Add extra short option
116 $resolver->setAllowedTypes('short', 'boolean');
122 public function getName(): string {
123 return 'rapsysair_snippet';