Completed
Pull Request — 3.1 (#348)
by Piotr
09:36 queued 07:40
created

Configuration   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 61
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B getConfigTreeBuilder() 0 58 4
1
<?php
2
3
/**
4
 * (c) FSi sp. z o.o. <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace FSi\Bundle\AdminBundle\DependencyInjection;
13
14
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
15
use Symfony\Component\Config\Definition\ConfigurationInterface;
16
17
class Configuration implements ConfigurationInterface
18
{
19
    public function getConfigTreeBuilder(): TreeBuilder
20
    {
21
        if (true === method_exists(TreeBuilder::class, 'getRootNode')) {
22
            $treeBuilder = new TreeBuilder('fsi_admin');
23
            $rootNode = $treeBuilder->getRootNode();
24
        } else {
25
            $treeBuilder = new TreeBuilder();
26
            $rootNode = $treeBuilder->root('fsi_admin');
27
        }
28
29
        $rootNode
30
            ->validate()
31
                ->always(function($v) {
32
                    if (!isset($v['templates']['crud_list'])) {
33
                        $v['templates']['crud_list'] = $v['templates']['list'];
34
                    }
35
                    if (!isset($v['templates']['crud_form'])) {
36
                        $v['templates']['crud_form'] = $v['templates']['form'];
37
                    }
38
                    return $v;
39
                })
40
            ->end()
41
            ->children()
42
                ->scalarNode('default_locale')->defaultValue('%locale%')->end()
43
                ->arrayNode('locales')
44
                    ->prototype('scalar')->end()
45
                    ->defaultValue(['%locale%'])
46
                ->end()
47
                ->scalarNode('menu_config_path')->defaultValue("%kernel.root_dir%/config/admin_menu.yml")->end()
48
                ->arrayNode('templates')
49
                    ->addDefaultsIfNotSet()
50
                    ->children()
51
                        ->scalarNode('base')->defaultValue('@FSiAdmin/base.html.twig')->end()
52
                        ->scalarNode('index_page')->defaultValue('@FSiAdmin/Admin/index.html.twig')->end()
53
                        ->scalarNode('list')->defaultValue('@FSiAdmin/List/list.html.twig')->end()
54
                        ->scalarNode('form')->defaultValue('@FSiAdmin/Form/form.html.twig')->end()
55
                        ->scalarNode('crud_list')->defaultValue('@FSiAdmin/CRUD/list.html.twig')->end()
56
                        ->scalarNode('crud_form')->defaultNull()->end()
57
                        ->scalarNode('resource')->defaultValue('@FSiAdmin/Resource/resource.html.twig')->end()
58
                        ->scalarNode('display')->defaultValue('@FSiAdmin/Display/display.html.twig')->end()
59
                        ->scalarNode('datagrid_theme')->defaultValue('@FSiAdmin/CRUD/datagrid.html.twig')->end()
60
                        ->scalarNode('datasource_theme')->defaultValue('@FSiAdmin/CRUD/datasource.html.twig')->end()
61
                        ->scalarNode('form_theme')->defaultValue('@FSiAdmin/Form/form_theme.html.twig')->end()
62
                    ->end()
63
                ->end()
64
                ->arrayNode('annotations')
65
                    ->addDefaultsIfNotSet()
66
                    ->children()
67
                        ->arrayNode('dirs')
68
                            ->prototype('scalar')->defaultValue([])->end()
69
                        ->end()
70
                    ->end()
71
                ->end()
72
            ->end()
73
        ;
74
75
        return $treeBuilder;
76
    }
77
}
78