]> Raphaël G. Git Repositories - airbundle/blobdiff - Form/LocationType.php
Add default locations_link and locations_title
[airbundle] / Form / LocationType.php
index 53784a996abbc65834f1109b6c729ca9f014ce66..ad4b94579d01861d57a2becdcbe30813a90a88d6 100644 (file)
@@ -1,55 +1,53 @@
-<?php
+<?php declare(strict_types=1);
+
+/*
+ * This file is part of the Rapsys AirBundle package.
+ *
+ * (c) Raphaël Gertz <symfony@rapsys.eu>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
 
 namespace Rapsys\AirBundle\Form;
 
 use Symfony\Component\Form\AbstractType;
-use Symfony\Component\Form\FormView;
-use Symfony\Component\Form\FormInterface;
-use Symfony\Component\Form\FormBuilderInterface;
-use Symfony\Component\OptionsResolver\OptionsResolver;
-use Symfony\Component\Form\Extension\Core\Type\TextType;
-use Symfony\Component\Form\Extension\Core\Type\NumberType;
 use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
+use Symfony\Component\Form\Extension\Core\Type\NumberType;
 use Symfony\Component\Form\Extension\Core\Type\SubmitType;
+use Symfony\Component\Form\Extension\Core\Type\TextareaType;
+use Symfony\Component\Form\Extension\Core\Type\TextType;
+use Symfony\Component\Form\FormBuilderInterface;
+use Symfony\Component\OptionsResolver\OptionsResolver;
 use Symfony\Component\Validator\Constraints\NotBlank;
+
 use Rapsys\AirBundle\Entity\Location;
 
+/**
+ * {@inheritdoc}
+ */
 class LocationType extends AbstractType {
        /**
         * {@inheritdoc}
         */
        public function buildForm(FormBuilderInterface $builder, array $options) {
                return $builder
-                       ->setAttribute('label_prefix', $options['label_prefix'])
-                       ->add('title', TextType::class, ['attr' => ['placeholder' => 'Your title']])
-                       ->add('short', TextType::class, ['attr' => ['placeholder' => 'Your short']])
-                       ->add('address', TextType::class, ['attr' => ['placeholder' => 'Your address']])
-                       ->add('zipcode', NumberType::class, ['attr' => ['placeholder' => 'Your zipcode'], 'html5' => true])
-                       ->add('city', TextType::class, ['attr' => ['placeholder' => 'Your city']])
-                       ->add('latitude', NumberType::class, ['attr' => ['placeholder' => 'Your latitude', 'step' => 0.000001], 'html5' => true, 'scale' => 6])
-                       ->add('longitude', NumberType::class, ['attr' => ['placeholder' => 'Your longitude', 'step' => 0.000001], 'html5' => true, 'scale' => 6])
+                       ->add('title', TextType::class, ['attr' => ['placeholder' => 'Your title'], 'constraints' => [new NotBlank(['message' => 'Please provide your title'])]])
+                       ->add('description', TextareaType::class, ['attr' => ['placeholder' => 'Your description', 'cols' => 50, 'rows' => 15], 'required' => false])
+                       ->add('address', TextType::class, ['attr' => ['placeholder' => 'Your address'], 'constraints' => [new NotBlank(['message' => 'Please provide your address'])]])
+                       ->add('zipcode', NumberType::class, ['attr' => ['placeholder' => 'Your zipcode'], 'html5' => true, 'constraints' => [new NotBlank(['message' => 'Please provide your zipcode'])]])
+                       ->add('city', TextType::class, ['attr' => ['placeholder' => 'Your city'], 'constraints' => [new NotBlank(['message' => 'Please provide your city'])]])
+                       ->add('latitude', NumberType::class, ['attr' => ['placeholder' => 'Your latitude', 'step' => 0.000001], 'html5' => true, 'scale' => 6, 'constraints' => [new NotBlank(['message' => 'Please provide your latitude'])]])
+                       ->add('longitude', NumberType::class, ['attr' => ['placeholder' => 'Your longitude', 'step' => 0.000001], 'html5' => true, 'scale' => 6, 'constraints' => [new NotBlank(['message' => 'Please provide your longitude'])]])
+                       ->add('indoor', CheckboxType::class, ['attr' => ['placeholder' => 'Your indoor'], 'required' => false])
                        ->add('hotspot', CheckboxType::class, ['attr' => ['placeholder' => 'Your hotspot'], 'required' => false])
                        ->add('submit', SubmitType::class, ['label' => 'Send', 'attr' => ['class' => 'submit']]);
        }
 
-       /**
-        * {@inheritdoc}
-        *
-       public function buildView(FormView $view, FormInterface $form, array $options) {
-               #$labelPrefix = $form->getRoot()->hasAttribute('label_prefix') ? $form->getRoot()->getAttribute('label_prefix') : '';
-               #$labelPrefix = $form->getConfig()->hasAttribute('label_prefix');
-               #$labelPrefix = $form->getConfig()->getAttribute('label_prefix');
-               #var_dump($view);
-               var_dump($view['label']);
-               exit;
-               //Prefix label to prevent collision
-               $view['label'] = $form->getConfig()->getAttribute('label_prefix').$view->getVar('label');
-       }*/
-
        /**
         * {@inheritdoc}
         */
        public function configureOptions(OptionsResolver $resolver) {
-               $resolver->setDefaults(['data_class' => Location::class, 'error_bubbling' => true, 'label_prefix' => '']);
+               $resolver->setDefaults(['data_class' => Location::class, 'error_bubbling' => true]);
        }
 }