]> Raphaƫl G. Git Repositories - airbundle/blob - Form/SnippetType.php
Add mail content-language
[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\FileType;
7 use Symfony\Component\Form\Extension\Core\Type\HiddenType;
8 use Symfony\Component\Form\Extension\Core\Type\NumberType;
9 use Symfony\Component\Form\Extension\Core\Type\SubmitType;
10 use Symfony\Component\Form\Extension\Core\Type\TextareaType;
11 use Symfony\Component\Form\Extension\Core\Type\TextType;
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('contact', UrlType::class, ['attr' => ['placeholder' => 'Your contact'], 'required' => false])
37 ->add('donate', UrlType::class, ['attr' => ['placeholder' => 'Your donate'], 'required' => false])
38 ->add('link', UrlType::class, ['attr' => ['placeholder' => 'Your link'], 'required' => false])
39 ->add('profile', UrlType::class, ['attr' => ['placeholder' => 'Your profile'], 'required' => false])
40 ->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])
41 ->add('submit', SubmitType::class, ['label' => 'Send', 'attr' => ['class' => 'submit']]);
42 }
43
44 /**
45 * {@inheritdoc}
46 */
47 public function configureOptions(OptionsResolver $resolver) {
48 $resolver->setDefaults(['data_class' => Snippet::class, 'error_bubbling' => true, 'location' => null, 'user' => null]);
49 $resolver->setAllowedTypes('location', [Location::class, 'null']);
50 $resolver->setAllowedTypes('user', [User::class, 'null']);
51 }
52
53 /**
54 * {@inheritdoc}
55 * XXX: this doesn't work, because it's impossible to generate this same id on other side
56 * TODO: we would need to be able to generate this id at form creation
57 *
58 public function getBlockPrefix() {
59 //Prevent collision between instances with an unique block prefix
60 return 'snippet_'.uniqid();
61 }*/
62 }