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

UpdateAreaFieldSubscriber::onLocalityChanged()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 12
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 18
rs 9.8666
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