Test Failed
Branch master (354693)
by Valery
12:29
created

UpdateAreaFieldSubscriber   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 25
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A onLocalityChanged() 0 18 2
A getSubscribedEvents() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Form\EventSubscriber;
6
7
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
8
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
9
use Symfony\Component\Form\FormEvent;
10
use Symfony\Component\Form\FormEvents;
11
12
class UpdateAreaFieldSubscriber implements EventSubscriberInterface
13
{
14
    public static function getSubscribedEvents()
15
    {
16
        return [FormEvents::POST_SUBMIT => 'onLocalityChanged'];
17
    }
18
19
    public function onLocalityChanged(FormEvent $event)
20
    {
21
        $form = $event->getForm();
22
23
        if ($form->getData()) {
24
            // Areas of the city
25
            $areas = $form->getData()->getAreas();
26
27
            $form->getParent()->add('area', EntityType::class, [
28
                'class' => 'App\Entity\Area',
29
                'placeholder' => 'placeholder.select_area',
30
                'choice_label' => 'name',
31
                'attr' => [
32
                    'class' => 'form-control',
33
                ],
34
                'required' => false,
35
                'label' => 'label.area',
36
                'choices' => $areas,
37
            ]);
38
        }
39
    }
40
}
41