Completed
Push — master ( a54a4b...bbfdca )
by Adam
15:54
created

ClientGroupFormBuilder   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getAlias() 0 4 1
A buildForm() 0 67 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
namespace WellCommerce\Bundle\AppBundle\Form\Admin;
13
14
use WellCommerce\Bundle\CoreBundle\Form\AbstractFormBuilder;
15
use WellCommerce\Component\Form\Elements\FormInterface;
16
17
/**
18
 * Class ClientGroupFormBuilder
19
 *
20
 * @author  Adam Piotrowski <[email protected]>
21
 */
22
class ClientGroupFormBuilder extends AbstractFormBuilder
23
{
24
    public function getAlias(): string
25
    {
26
        return 'admin.client_group';
27
    }
28
    
29
    public function buildForm(FormInterface $form)
30
    {
31
        $requiredData = $form->addChild($this->getElement('nested_fieldset', [
32
            'name'  => 'required_data',
33
            'label' => 'common.fieldset.general',
34
        ]));
35
        
36
        $languageData = $requiredData->addChild($this->getElement('language_fieldset', [
37
            'name'        => 'translations',
38
            'label'       => 'common.fieldset.translations',
39
            'transformer' => $this->getRepositoryTransformer('translation', $this->get('client_group.repository')),
40
        ]));
41
        
42
        $languageData->addChild($this->getElement('text_field', [
43
            'name'  => 'name',
44
            'label' => 'common.label.name',
45
            'rules' => [
46
                $this->getRule('required'),
47
            ],
48
        ]));
49
        
50
        $discountSettings = $form->addChild($this->getElement('nested_fieldset', [
51
            'name'  => 'discount_data',
52
            'label' => 'common.fieldset.discount_settings',
53
        ]));
54
        
55
        $discountSettings->addChild($this->getElement('tip', [
56
            'tip' => 'common.tip.discount_expression',
57
        ]));
58
        
59
        $discountSettings->addChild($this->getElement('text_field', [
60
            'name'   => 'discount',
61
            'label'  => 'common.label.discount',
62
            'suffix' => '%',
63
        ]));
64
        
65
        $minimumOrderAmount = $form->addChild($this->getElement('nested_fieldset', [
66
            'name'  => 'minimumOrderAmount',
67
            'label' => 'common.fieldset.minimum_order_amount',
68
        ]));
69
        
70
        $minimumOrderAmount->addChild($this->getElement('text_field', [
71
            'name'    => 'minimumOrderAmount.value',
72
            'label'   => 'common.label.minimum_order_amount.value',
73
            'suffix'  => '%',
74
            'filters' => [
75
                $this->getFilter('comma_to_dot_changer'),
76
            ],
77
            'rules'   => [
78
                $this->getRule('required'),
79
            ],
80
            'default' => 0,
81
        ]));
82
        
83
        $minimumOrderAmount->addChild($this->getElement('select', [
84
            'name'    => 'minimumOrderAmount.currency',
85
            'label'   => 'common.label.minimum_order_amount.currency',
86
            'options' => $this->get('currency.dataset.admin')->getResult('select', ['order_by' => 'code'], [
87
                'label_column' => 'code',
88
                'value_column' => 'code',
89
            ]),
90
        ]));
91
        
92
        $form->addFilter($this->getFilter('no_code'));
93
        $form->addFilter($this->getFilter('trim'));
94
        $form->addFilter($this->getFilter('secure'));
95
    }
96
}
97