3 namespace Rapsys\AirBundle\Form
;
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
;
19 class SnippetType
extends AbstractType
{
23 public function buildForm(FormBuilderInterface
$builder, array $options) {
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']]);
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']);
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
51 public function getBlockPrefix() {
52 //Prevent collision between instances with an unique block prefix
53 return 'snippet_'.uniqid();