Completed
Push — master ( d67f41...79042b )
by Adam
07:27
created

LayoutBoxFormBuilder::buildForm()   A

Complexity

Conditions 1
Paths 1

Duplication

Lines 0
Ratio 0 %

Size

Total Lines 51
Code Lines 33

Importance

Changes 0
Metric Value
dl 0
loc 51
rs 9.4109
c 0
b 0
f 0
cc 1
eloc 33
nc 1
nop 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 LayoutBoxFormBuilder
19
 *
20
 * @author Adam Piotrowski <[email protected]>
21
 */
22
class LayoutBoxFormBuilder extends AbstractFormBuilder
23
{
24
    public function getAlias(): string
25
    {
26
        return 'admin.layout_box';
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('layout_box.repository'))
40
        ]));
41
        
42
        $languageData->addChild($this->getElement('text_field', [
43
            'name'  => 'name',
44
            'label' => 'layout_box.label.name',
45
            'rules' => [
46
                $this->getRule('required')
47
            ],
48
        ]));
49
    
50
        $languageData->addChild($this->getElement('rich_text_editor', [
51
            'name'  => 'content',
52
            'label' => 'layout_box.label.content'
53
        ]));
54
        
55
        $requiredData->addChild($this->getElement('text_field', [
56
            'name'    => 'identifier',
57
            'label'   => 'layout_box.label.identifier',
58
            'rules'   => [
59
                $this->getRule('required')
60
            ],
61
        ]));
62
        
63
        $requiredData->addChild($this->getElement('select', [
64
            'name'    => 'boxType',
65
            'label'   => 'layout_box.label.type',
66
            'default' => $this->getDefaultLayoutBoxType()
67
        ]));
68
    
69
        $requiredData->addChild($this->getElement('multi_select', [
70
            'name'        => 'clientGroups',
71
            'label'       => 'layout_box.label.client_groups',
72
            'options'     => $this->get('client_group.dataset.admin')->getResult('select'),
73
            'transformer' => $this->getRepositoryTransformer('collection', $this->get('client_group.repository')),
74
        ]));
75
        
76
        $form->addFilter($this->getFilter('no_code'));
77
        $form->addFilter($this->getFilter('trim'));
78
        $form->addFilter($this->getFilter('secure'));
79
    }
80
    
81
    private function getDefaultLayoutBoxType() : string
82
    {
83
        $type = $this->container->get('layout_box.configurator.collection')->first();
84
        
85
        return $type->getType();
86
    }
87
}
88