Completed
Pull Request — 3.x (#978)
by
unknown
01:40
created

Configuration::getFiltersNode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 9.456
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\DoctrineORMAdminBundle\DependencyInjection;
15
16
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
17
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
18
use Symfony\Component\Config\Definition\ConfigurationInterface;
19
20
/**
21
 * This class contains the configuration information for the bundle.
22
 *
23
 * This information is solely responsible for how the different configuration
24
 * sections are normalized, and merged.
25
 *
26
 * @author Michael Williams <[email protected]>
27
 */
28
class Configuration implements ConfigurationInterface
29
{
30
    /**
31
     * Generates the configuration tree.
32
     *
33
     * @return TreeBuilder
34
     */
35
    public function getConfigTreeBuilder()
36
    {
37
        $treeBuilder = new TreeBuilder('sonata_doctrine_orm_admin');
38
39
        // Keep compatibility with symfony/config < 4.2
40
        if (!method_exists($treeBuilder, 'getRootNode')) {
41
            $rootNode = $treeBuilder->root('sonata_doctrine_orm_admin');
0 ignored issues
show
Deprecated Code introduced by
The method Symfony\Component\Config...der\TreeBuilder::root() has been deprecated with message: since Symfony 4.3, pass the root name to the constructor instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
42
        } else {
43
            $rootNode = $treeBuilder->getRootNode();
44
        }
45
46
        $rootNode
47
            ->children()
48
                ->scalarNode('entity_manager')->defaultNull()->end()
49
                ->arrayNode('audit')
50
                    ->addDefaultsIfNotSet()
51
                    ->children()
52
                        ->booleanNode('force')->defaultTrue()->end()
53
                    ->end()
54
                ->end()
55
                ->arrayNode('templates')
56
                    ->addDefaultsIfNotSet()
57
                    ->children()
58
                        ->arrayNode('form')
59
                            ->prototype('scalar')->end()
60
                            ->defaultValue(['@SonataDoctrineORMAdmin/Form/form_admin_fields.html.twig'])
61
                        ->end()
62
                        ->arrayNode('filter')
63
                            ->prototype('scalar')->end()
64
                            ->defaultValue(['@SonataDoctrineORMAdmin/Form/filter_admin_fields.html.twig'])
65
                        ->end()
66
                        ->arrayNode('types')
67
                            ->children()
68
                                ->arrayNode('list')
69
                                    ->useAttributeAsKey('name')
70
                                    ->prototype('scalar')->end()
71
                                ->end()
72
                                ->arrayNode('show')
73
                                    ->useAttributeAsKey('name')
74
                                    ->prototype('scalar')->end()
75
                                ->end()
76
                            ->end()
77
                        ->end()
78
                    ->end()
79
                ->end()
80
            ->end()
81
            ->append($this->getFiltersNode())
82
        ;
83
84
        return $treeBuilder;
85
    }
86
87
    private function getFiltersNode(): ArrayNodeDefinition
88
    {
89
        $treeBuilder = new TreeBuilder();
90
        $node = $treeBuilder->root('filters');
0 ignored issues
show
Deprecated Code introduced by
The method Symfony\Component\Config...der\TreeBuilder::root() has been deprecated with message: since Symfony 4.3, pass the root name to the constructor instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
91
92
        $caseSensitiveInfo = <<<'CASESENSITIVE'
93
Whether the StringFilter should behave case sensitive or not.
94
Using case-insensitivity might lead to performance issues.
95
See https://use-the-index-luke.com/sql/where-clause/functions/case-insensitive-search
96
for more information.
97
CASESENSITIVE;
98
99
        $node
100
            ->addDefaultsIfNotSet()
101
            ->children()
102
                ->arrayNode('string')
103
                    ->addDefaultsIfNotSet()
104
                    ->children()
105
                        ->booleanNode('case_sensitive')
106
                            ->defaultTrue()
107
                            ->info($caseSensitiveInfo)
108
                        ->end()
109
                    ->end()
110
                ->end()
111
            ->end()
112
        ;
113
114
        return $node;
115
    }
116
}
117