]> Raphaƫl G. Git Repositories - airbundle/blob - Form/LocationType.php
Add register template
[airbundle] / Form / LocationType.php
1 <?php
2
3 namespace Rapsys\AirBundle\Form;
4
5 use Symfony\Component\Form\AbstractType;
6 use Symfony\Component\Form\FormView;
7 use Symfony\Component\Form\FormInterface;
8 use Symfony\Component\Form\FormBuilderInterface;
9 use Symfony\Component\OptionsResolver\OptionsResolver;
10 use Symfony\Component\Form\Extension\Core\Type\TextType;
11 use Symfony\Component\Form\Extension\Core\Type\NumberType;
12 use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
13 use Symfony\Component\Form\Extension\Core\Type\SubmitType;
14 use Symfony\Component\Validator\Constraints\NotBlank;
15 use Rapsys\AirBundle\Entity\Location;
16
17 class LocationType extends AbstractType {
18 /**
19 * {@inheritdoc}
20 */
21 public function buildForm(FormBuilderInterface $builder, array $options) {
22 return $builder
23 ->setAttribute('label_prefix', $options['label_prefix'])
24 ->add('title', TextType::class, ['attr' => ['placeholder' => 'Your title']])
25 ->add('short', TextType::class, ['attr' => ['placeholder' => 'Your short']])
26 ->add('address', TextType::class, ['attr' => ['placeholder' => 'Your address']])
27 ->add('zipcode', NumberType::class, ['attr' => ['placeholder' => 'Your zipcode'], 'html5' => true])
28 ->add('city', TextType::class, ['attr' => ['placeholder' => 'Your city']])
29 ->add('latitude', NumberType::class, ['attr' => ['placeholder' => 'Your latitude', 'step' => 0.000001], 'html5' => true, 'scale' => 6])
30 ->add('longitude', NumberType::class, ['attr' => ['placeholder' => 'Your longitude', 'step' => 0.000001], 'html5' => true, 'scale' => 6])
31 ->add('hotspot', CheckboxType::class, ['attr' => ['placeholder' => 'Your hotspot'], 'required' => false])
32 ->add('submit', SubmitType::class, ['label' => 'Send', 'attr' => ['class' => 'submit']]);
33 }
34
35 /**
36 * {@inheritdoc}
37 *
38 public function buildView(FormView $view, FormInterface $form, array $options) {
39 #$labelPrefix = $form->getRoot()->hasAttribute('label_prefix') ? $form->getRoot()->getAttribute('label_prefix') : '';
40 #$labelPrefix = $form->getConfig()->hasAttribute('label_prefix');
41 #$labelPrefix = $form->getConfig()->getAttribute('label_prefix');
42 #var_dump($view);
43 var_dump($view['label']);
44 exit;
45 //Prefix label to prevent collision
46 $view['label'] = $form->getConfig()->getAttribute('label_prefix').$view->getVar('label');
47 }*/
48
49 /**
50 * {@inheritdoc}
51 */
52 public function configureOptions(OptionsResolver $resolver) {
53 $resolver->setDefaults(['data_class' => Location::class, 'error_bubbling' => true, 'label_prefix' => '']);
54 }
55 }