CategoryMenuBoxConfigurator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getType() 0 4 1
A addFormFields() 0 21 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\CatalogBundle\Service\Layout\Configurator;
14
15
use WellCommerce\Bundle\CatalogBundle\Controller\Box\CategoryMenuBoxController;
16
use WellCommerce\Bundle\CatalogBundle\DataSet\Admin\CategoryDataSet;
17
use WellCommerce\Bundle\CoreBundle\Layout\Configurator\AbstractLayoutBoxConfigurator;
18
use WellCommerce\Component\Form\Elements\FormInterface;
19
use WellCommerce\Component\Form\FormBuilderInterface;
20
21
/**
22
 * Class CategoryMenuBoxConfigurator
23
 *
24
 * @author  Adam Piotrowski <[email protected]>
25
 */
26
final class CategoryMenuBoxConfigurator extends AbstractLayoutBoxConfigurator
27
{
28
    /**
29
     * @var CategoryDataSet
30
     */
31
    private $dataSet;
32
    
33
    public function __construct(CategoryMenuBoxController $controller, CategoryDataSet $dataSet)
34
    {
35
        $this->controller = $controller;
36
        $this->dataSet    = $dataSet;
37
    }
38
    
39
    public function getType(): string
40
    {
41
        return 'CategoryMenu';
42
    }
43
    
44
    public function addFormFields(FormBuilderInterface $builder, FormInterface $form, $defaults)
45
    {
46
        $fieldset = $this->getFieldset($builder, $form);
47
        $accessor = $this->getPropertyAccessor();
48
        
49
        $fieldset->addChild($builder->getElement('tip', [
50
            'tip' => 'Choose categories which should be not visible in box.',
51
        ]));
52
        
53
        $exclude = $fieldset->addChild($builder->getElement('tree', [
54
            'name'       => 'exclude',
55
            'label'      => 'category.label.exclude',
56
            'choosable'  => false,
57
            'selectable' => true,
58
            'sortable'   => false,
59
            'clickable'  => false,
60
            'items'      => $this->dataSet->getResult('flat_tree'),
61
        ]));
62
        
63
        $exclude->setValue($accessor->getValue($defaults, '[exclude]'));
64
    }
65
}
66