Completed
Branch master (b7eb35)
by Arnaud
02:59
created

Configuration::getAdminsConfigurationNode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 1

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 0
loc 23
ccs 15
cts 15
cp 1
rs 9.0856
c 1
b 1
f 0
cc 1
eloc 16
nc 1
nop 0
crap 1
1
<?php
2
3
namespace LAG\AdminBundle\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
6
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
7
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
8
use Symfony\Component\Config\Definition\ConfigurationInterface;
9
10
class Configuration implements ConfigurationInterface
11
{
12
    /**
13
     * @return TreeBuilder
14
     */
15 4
    public function getConfigTreeBuilder()
16
    {
17 4
        $treeBuilder = new TreeBuilder();
18 4
        $rootNode = $treeBuilder->root('lag_admin');
19
20
        $rootNode
21 4
            ->children()
22
                // application configuration
23 4
                ->append($this->getApplicationNode())
24
                // admins configuration
25 4
                ->append($this->getAdminsConfigurationNode())
26
                // menus configurations
27 4
                ->append($this->getMenuConfiguration())
28 4
            ->end()
29 4
        ->end();
30
31 4
        return $treeBuilder;
32
    }
33
34
    /**
35
     * @return ArrayNodeDefinition|NodeDefinition
36
     */
37 4
    protected function getAdminsConfigurationNode()
38
    {
39 4
        $builder = new TreeBuilder();
40 4
        $node = $builder->root('admins');
41
42
        $node
43
            // useAttributeAsKey() method will preserve keys when multiple configurations files are used and then avoid
44
            // admin not found by configuration override
45 4
            ->useAttributeAsKey('name')
46 4
            ->prototype('array')
47 4
                ->children()
48 4
                    ->scalarNode('entity')->end()
49 4
                    ->scalarNode('data_provider')->end()
50 4
                    ->scalarNode('form')->end()
51 4
                    ->scalarNode('max_per_page')->end()
52 4
                    ->scalarNode('controller')->defaultValue('LAGAdminBundle:CRUD')->end()
53
                    // actions configurations
54 4
                    ->variableNode('actions')->end()
55 4
                ->end()
56 4
            ->end();
57
58 4
        return $node;
59
    }
60
61
    /**
62
     * @return ArrayNodeDefinition|NodeDefinition
63
     */
64 4
    protected function getApplicationNode()
65
    {
66 4
        $builder = new TreeBuilder();
67 4
        $node = $builder->root('application');
68
69
        $node
70 4
            ->children()
71 4
                ->scalarNode('title')->end()
72 4
                ->scalarNode('description')->end()
73 4
                ->scalarNode('base_template')->end()
74 4
                ->scalarNode('date_format')->defaultValue('Y-m-d')->end()
75 4
                ->scalarNode('bootstrap')->end()
76 4
                ->scalarNode('max_per_page')->end()
77 4
                ->arrayNode('routing')
78 4
                    ->children()
79 4
                        ->scalarNode('name_pattern')->end()
80 4
                        ->scalarNode('url_pattern')->end()
81 4
                    ->end()
82 4
                ->end()
83 4
                ->arrayNode('translation')
84 4
                    ->canBeDisabled()
85 4
                    ->children()
86 4
                        ->scalarNode('pattern')->end()
87 4
                    ->end()
88 4
                ->end()
89 4
                ->scalarNode('block_template')
90 4
                    ->defaultValue('LAGAdminBundle:Form:fields.html.twig')
91 4
                ->end()
92 4
                ->arrayNode('fields_mapping')
93 4
                    ->prototype('scalar')
94 4
                    ->end()
95 4
                ->end()
96 4
                ->variableNode('menus')->end()
97 4
            ->end()
98 4
        ->end();
99
100 4
        return $node;
101
    }
102
103
    /**
104
     * @return ArrayNodeDefinition|NodeDefinition
105
     */
106 4
    protected function getMenuConfiguration()
107
    {
108 4
        $builder = new TreeBuilder();
109 4
        $node = $builder->root('menus');
110
111
        $node
112 4
            ->prototype('variable')
113 4
            ->end()
114 4
        ->end();
115
116 4
        return $node;
117
    }
118
}
119