WanderType   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 32
c 3
b 0
f 0
dl 0
loc 50
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A buildForm() 0 41 3
A configureOptions() 0 5 1
1
<?php
2
3
namespace App\Form;
4
5
use App\Entity\Image;
6
use App\Entity\Wander;
7
use Doctrine\ORM\EntityRepository;
8
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
9
use Symfony\Component\Form\AbstractType;
10
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
11
use Symfony\Component\Form\FormBuilderInterface;
12
use Symfony\Component\OptionsResolver\OptionsResolver;
13
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
14
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
15
use Symfony\Component\Form\Extension\Core\Type\TextType;
16
use Symfony\Component\Validator\Constraints\File;
17
use Symfony\Component\Form\Extension\Core\Type\FileType;
18
19
class WanderType extends AbstractType
20
{
21
    public function buildForm(FormBuilderInterface $builder, array $options)
22
    {
23
        $builder
24
            ->add('title', TextType::class)
25
            ->add('description', TextareaType::class, [
26
                'attr' => ['rows' => 10]
27
            ]);
28
        if ('standard' === $options['type']) {
29
            /** @var Wander */
30
            $wander = $builder->getData();
31
            $builder
32
                ->add('startTime', DateTimeType::class)
33
                ->add('endTime', DateTimeType::class)
34
                ->add('gpxFilename', TextType::class, ['label' => 'GPX Filename', 'disabled' => true])
35
                ->add('featuredImage', EntityType::class, [
36
                    'required' => false,
37
                    'class' => Image::class,
38
                    'choices' => $wander->getImages(),
39
                    'multiple' => false,
40
                ]);
41
42
        } elseif ('new' === $options['type']) {
43
            // Our form for new Wanders includes a GPX file upload. We don't
44
            // let anything else change that.
45
            $builder
46
                ->add('gpxFilename', FileType::class, [
47
                    'label' => 'GPX track file',
48
                    'mapped' => false,
49
                    'constraints' => [
50
                        new File([
51
                            'maxSize' => '1024k',
52
                            'mimeTypes' => [
53
                                "application/gpx+xml","text/xml","application/xml","application/octet-stream"
54
                            ],
55
                            'mimeTypesMessage' =>'Please upload a valid GPX document'
56
                        ])
57
                    ],
58
                ]);
59
        }
60
        $builder
61
            ->add('save', SubmitType::class, ['label' => 'Save']);
62
    }
63
64
    public function configureOptions(OptionsResolver $resolver)
65
    {
66
        $resolver->setDefaults([
67
            'data_class' => Wander::class,
68
            'type' => 'standard'
69
        ]);
70
    }
71
}
72