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