ContactFormBuilder   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 106
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 5
dl 0
loc 106
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getAlias() 0 4 1
B buildForm() 0 98 1
1
<?php
2
/*
3
 * WellCommerce Open-Source E-Commerce Platform
4
 *
5
 * This file is part of the WellCommerce package.
6
 *
7
 * (c) Adam Piotrowski <[email protected]>
8
 *
9
 * For the full copyright and license information,
10
 * please view the LICENSE file that was distributed with this source code.
11
 */
12
13
namespace WellCommerce\Bundle\CmsBundle\Form\Admin;
14
15
use WellCommerce\Bundle\CoreBundle\Form\AbstractFormBuilder;
16
use WellCommerce\Component\Form\Elements\FormInterface;
17
18
/**
19
 * Class ContactFormBuilder
20
 *
21
 * @author  Adam Piotrowski <[email protected]>
22
 */
23
class ContactFormBuilder extends AbstractFormBuilder
24
{
25
    public function getAlias(): string
26
    {
27
        return 'admin.contact';
28
    }
29
    
30
    public function buildForm(FormInterface $form)
31
    {
32
        $requiredData = $form->addChild($this->getElement('nested_fieldset', [
33
            'name'  => 'requiredData',
34
            'label' => 'common.fieldset.general',
35
        ]));
36
        
37
        $requiredData->addChild($this->getElement('checkbox', [
38
            'name'  => 'enabled',
39
            'label' => 'common.label.enabled',
40
        ]));
41
        
42
        $languageData = $requiredData->addChild($this->getElement('language_fieldset', [
43
            'name'        => 'translations',
44
            'label'       => 'common.fieldset.translations',
45
            'transformer' => $this->getRepositoryTransformer('translation', $this->get('contact.repository')),
46
        ]));
47
        
48
        $languageData->addChild($this->getElement('text_field', [
49
            'name'  => 'name',
50
            'label' => 'common.label.name',
51
            'rules' => [
52
                $this->getRule('required'),
53
            ],
54
        ]));
55
    
56
        $languageData->addChild($this->getElement('text_field', [
57
            'name'  => 'topic',
58
            'label' => 'contact.label.topic',
59
            'rules' => [
60
                $this->getRule('required'),
61
            ],
62
        ]));
63
        
64
        $languageData->addChild($this->getElement('text_field', [
65
            'name'  => 'email',
66
            'label' => 'common.label.email',
67
            'rules' => [
68
                $this->getRule('required'),
69
            ],
70
        ]));
71
        
72
        $languageData->addChild($this->getElement('text_field', [
73
            'name'  => 'phone',
74
            'label' => 'common.label.phone',
75
            'rules' => [
76
                $this->getRule('required'),
77
            ],
78
        ]));
79
        
80
        $languageData->addChild($this->getElement('text_area', [
81
            'name'  => 'businessHours',
82
            'label' => 'contact.label.business_hours',
83
        ]));
84
        
85
        $addressData = $form->addChild($this->getElement('nested_fieldset', [
86
            'name'  => 'addressData',
87
            'label' => 'common.label.address',
88
        ]));
89
        
90
        $addressData->addChild($this->getElement('text_field', [
91
            'name'  => 'line1',
92
            'label' => 'address.label.line1',
93
        ]));
94
        
95
        $addressData->addChild($this->getElement('text_field', [
96
            'name'  => 'line2',
97
            'label' => 'address.label.line2',
98
        ]));
99
        
100
        $addressData->addChild($this->getElement('text_field', [
101
            'name'  => 'state',
102
            'label' => 'address.label.state',
103
        ]));
104
        
105
        $addressData->addChild($this->getElement('text_field', [
106
            'name'  => 'postalCode',
107
            'label' => 'address.label.post_code',
108
        ]));
109
        
110
        $addressData->addChild($this->getElement('text_field', [
111
            'name'  => 'city',
112
            'label' => 'address.label.city',
113
        ]));
114
        
115
        $addressData->addChild($this->getElement('select', [
116
            'name'    => 'country',
117
            'label'   => 'address.label.country',
118
            'options' => $this->get('country.repository')->all(),
119
            'default' => $this->getShopStorage()->getCurrentShop()->getDefaultCountry(),
120
        ]));
121
        
122
        $this->addShopsFieldset($form);
123
        
124
        $form->addFilter($this->getFilter('no_code'));
125
        $form->addFilter($this->getFilter('trim'));
126
        $form->addFilter($this->getFilter('secure'));
127
    }
128
}
129