]> Raphaƫl G. Git Repositories - airbundle/blob - Form/SnippetType.php
Add calendar default config
[airbundle] / Form / SnippetType.php
1 <?php
2
3 namespace Rapsys\AirBundle\Form;
4
5 use Symfony\Component\Form\AbstractType;
6 use Symfony\Component\Form\FormBuilderInterface;
7 use Symfony\Component\OptionsResolver\OptionsResolver;
8 use Symfony\Component\Form\Extension\Core\Type\HiddenType;
9 use Symfony\Component\Form\Extension\Core\Type\TextType;
10 use Symfony\Component\Form\Extension\Core\Type\TextareaType;
11 use Symfony\Component\Form\Extension\Core\Type\UrlType;
12 use Symfony\Component\Form\Extension\Core\Type\SubmitType;
13 use Symfony\Component\Validator\Constraints\NotBlank;
14 use Rapsys\AirBundle\Form\Extension\Type\HiddenEntityType;
15 use Rapsys\AirBundle\Entity\Location;
16 use Rapsys\AirBundle\Entity\User;
17 use Rapsys\AirBundle\Entity\Snippet;
18
19 class SnippetType extends AbstractType {
20 /**
21 * {@inheritdoc}
22 */
23 public function buildForm(FormBuilderInterface $builder, array $options) {
24 return $builder
25 ->add('locale', HiddenType::class, ['required' => true])
26 ->add('location', HiddenEntityType::class, ['required' => true])
27 ->add('user', HiddenEntityType::class, ['required' => true])
28 ->add('description', TextareaType::class, ['attr' => ['placeholder' => 'Your description', 'cols' => 50, 'rows' => 15], 'constraints' => [new NotBlank(['message' => 'Please provide your description'])], 'required' => true])
29 ->add('class', TextareaType::class, ['attr' => ['placeholder' => 'Your class', 'cols' => 50, 'rows' => 15], 'required' => false])
30 ->add('contact', UrlType::class, ['attr' => ['placeholder' => 'Your contact'], 'required' => false])
31 ->add('donate', UrlType::class, ['attr' => ['placeholder' => 'Your donate'], 'required' => false])
32 ->add('link', UrlType::class, ['attr' => ['placeholder' => 'Your link'], 'required' => false])
33 ->add('profile', UrlType::class, ['attr' => ['placeholder' => 'Your profile'], 'required' => false])
34 ->add('submit', SubmitType::class, ['label' => 'Send', 'attr' => ['class' => 'submit']]);
35 }
36
37 /**
38 * {@inheritdoc}
39 */
40 public function configureOptions(OptionsResolver $resolver) {
41 $resolver->setDefaults(['data_class' => Snippet::class, 'error_bubbling' => true, 'location' => null, 'user' => null]);
42 $resolver->setAllowedTypes('location', [Location::class, 'null']);
43 $resolver->setAllowedTypes('user', [User::class, 'null']);
44 }
45
46 /**
47 * {@inheritdoc}
48 * XXX: this doesn't work, because it's impossible to generate this same id on other side
49 * TODO: we would need to be able to generate this id at form creation
50 *
51 public function getBlockPrefix() {
52 //Prevent collision between instances with an unique block prefix
53 return 'snippet_'.uniqid();
54 }*/
55 }