]> Raphaƫl G. Git Repositories - airbundle/blob - Form/SnippetType.php
Fix strict types
[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\TextType;
13 use Symfony\Component\Form\Extension\Core\Type\UrlType;
14 use Symfony\Component\Form\FormBuilderInterface;
15 use Symfony\Component\OptionsResolver\OptionsResolver;
16 use Symfony\Component\Validator\Constraints\File;
17 use Symfony\Component\Validator\Constraints\NotBlank;
18
19 use Rapsys\AirBundle\Form\Extension\Type\HiddenEntityType;
20 use Rapsys\AirBundle\Entity\Location;
21 use Rapsys\AirBundle\Entity\User;
22 use Rapsys\AirBundle\Entity\Snippet;
23
24 class SnippetType extends AbstractType {
25 /**
26 * {@inheritdoc}
27 */
28 public function buildForm(FormBuilderInterface $builder, array $options) {
29 return $builder
30 ->add('locale', HiddenType::class, ['required' => true])
31 ->add('location', HiddenEntityType::class, ['required' => true])
32 ->add('user', HiddenEntityType::class, ['required' => true])
33 ->add('description', TextareaType::class, ['attr' => ['placeholder' => 'Your description', 'cols' => 50, 'rows' => 15], 'required' => false])
34 ->add('class', TextareaType::class, ['attr' => ['placeholder' => 'Your class', 'cols' => 50, 'rows' => 10], 'required' => false])
35 ->add('short', TextareaType::class, ['attr' => ['placeholder' => 'Your short', 'cols' => 50, 'rows' => 10], 'required' => false])
36 ->add('rate', NumberType::class, ['attr' => ['placeholder' => 'Your rate'], 'required' => false])
37 ->add('hat', CheckboxType::class, ['attr' => ['placeholder' => 'Your hat'], 'required' => false])
38 ->add('contact', UrlType::class, ['attr' => ['placeholder' => 'Your contact'], 'required' => false])
39 ->add('donate', UrlType::class, ['attr' => ['placeholder' => 'Your donate'], 'required' => false])
40 ->add('link', UrlType::class, ['attr' => ['placeholder' => 'Your link'], 'required' => false])
41 ->add('profile', UrlType::class, ['attr' => ['placeholder' => 'Your profile'], 'required' => false])
42 ->add('image', FileType::class, ['attr' => ['placeholder' => 'Your image'], 'constraints' => [new File(['maxSize' => '5M', 'mimeTypes' => ['image/jpeg', 'image/png', 'image/tiff', 'image/webp'], 'mimeTypesMessage' => 'Please upload a valid Image document'])], 'mapped' => false, 'required' => false])
43 ->add('submit', SubmitType::class, ['label' => 'Send', 'attr' => ['class' => 'submit']]);
44 }
45
46 /**
47 * {@inheritdoc}
48 */
49 public function configureOptions(OptionsResolver $resolver) {
50 $resolver->setDefaults(['data_class' => Snippet::class, 'error_bubbling' => true, 'location' => null, 'user' => null]);
51 $resolver->setAllowedTypes('location', [Location::class, 'null']);
52 $resolver->setAllowedTypes('user', [User::class, 'null']);
53 }
54
55 /**
56 * {@inheritdoc}
57 * XXX: this doesn't work, because it's impossible to generate this same id on other side
58 * TODO: we would need to be able to generate this id at form creation
59 *
60 public function getBlockPrefix() {
61 //Prevent collision between instances with an unique block prefix
62 return 'snippet_'.uniqid();
63 }*/
64 }