]> Raphaƫl G. Git Repositories - airbundle/blob - Form/SnippetType.php
Remove link feature
[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\Bridge\Doctrine\Form\Type\EntityType;
9 use Symfony\Component\Form\Extension\Core\Type\HiddenType;
10 use Symfony\Component\Form\Extension\Core\Type\TextType;
11 use Symfony\Component\Form\Extension\Core\Type\TextareaType;
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('submit', SubmitType::class, ['label' => 'Send', 'attr' => ['class' => 'submit']]);
30 #->add('delete', SubmitType::class, ['label' => 'Remove', 'attr' => ['class' => 'submit']]);
31 }
32
33 /**
34 * {@inheritdoc}
35 */
36 public function configureOptions(OptionsResolver $resolver) {
37 $resolver->setDefaults(['data_class' => Snippet::class, 'error_bubbling' => true, 'location' => null, 'user' => null]);
38 $resolver->setAllowedTypes('location', [Location::class, 'null']);
39 $resolver->setAllowedTypes('user', [User::class, 'null']);
40 }
41
42 /**
43 * {@inheritdoc}
44 */
45 public function getName() {
46 return 'snippet_form';
47 }
48 }