Completed
Pull Request — 3.1 (#348)
by Piotr
20:24
created

SubscriberForm   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 55
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getClassName() 0 4 1
A getId() 0 4 1
A getSuccessRoute() 0 4 1
A getSuccessRouteParameters() 0 4 1
A initForm() 0 32 1
1
<?php
2
3
/**
4
 * (c) FSi sp. z o.o. <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace FSi\FixturesBundle\Admin;
13
14
use FSi\Bundle\AdminBundle\Doctrine\Admin\FormElement;
15
use FSi\FixturesBundle\Entity;
16
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
17
use Symfony\Component\Form\Extension\Core\Type\DateType;
18
use Symfony\Component\Form\Extension\Core\Type\EmailType;
19
use Symfony\Component\Form\Extension\Core\Type\FormType;
20
use Symfony\Component\Form\FormFactoryInterface;
21
use Symfony\Component\Form\FormInterface;
22
23
class SubscriberForm extends FormElement
24
{
25
    public function getClassName(): string
26
    {
27
        return Entity\Subscriber::class;
28
    }
29
30
    public function getId(): string
31
    {
32
        return 'subscriber_form';
33
    }
34
35
    public function getSuccessRoute(): string
36
    {
37
        return 'fsi_admin_list';
38
    }
39
40
    public function getSuccessRouteParameters(): array
41
    {
42
        return ['element' => 'subscriber'];
43
    }
44
45
    protected function initForm(FormFactoryInterface $factory, $data = null): FormInterface
46
    {
47
        $builder = $factory->createNamedBuilder(
48
            'subscriber',
49
            FormType::class,
50
            $data,
51
            ['data_class' => $this->getClassName()]
52
        );
53
54
        $builder->add(
55
            'email',
56
            EmailType::class,
57
            ['label' => 'admin.subscriber.list.email']
58
        );
59
60
        $builder->add(
61
            'created_at',
62
            DateType::class,
63
            [
64
                'label' => 'admin.subscriber.list.created_at',
65
                'widget' => 'single_text'
66
            ]
67
        );
68
69
        $builder->add(
70
            'active',
71
            CheckboxType::class,
72
            ['label' => 'admin.subscriber.list.active']
73
        );
74
75
        return $builder->getForm();
76
    }
77
}
78