Completed
Push — master ( b1c6ca...52cd2c )
by Kamil
77:57 queued 60:05
created

Configuration::getConfigTreeBuilder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 32
rs 9.408
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Sylius\Bundle\UiBundle\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
final class Configuration implements ConfigurationInterface
21
{
22
    public function getConfigTreeBuilder(): TreeBuilder
23
    {
24
        $treeBuilder = new TreeBuilder('sylius_ui');
25
        /** @var ArrayNodeDefinition $rootNode */
26
        $rootNode = $treeBuilder->getRootNode();
27
28
        $rootNode
29
            ->fixXmlConfig('event')
30
            ->children()
31
                ->arrayNode('events')
32
                    ->useAttributeAsKey('event_name')
33
                    ->arrayPrototype()
34
                        ->fixXmlConfig('block')
35
                        ->children()
36
                            ->arrayNode('blocks')
37
                                ->defaultValue([])
38
                                ->useAttributeAsKey('block_name')
39
                                ->arrayPrototype()
40
                                    ->canBeDisabled()
41
                                    ->beforeNormalization()
42
                                        ->ifString()
43
                                        ->then(static function (string $template): array {
44
                                            return ['template' => $template];
45
                                        })
46
                                    ->end()
47
                                    ->children()
48
                                        ->scalarNode('template')->isRequired()->cannotBeEmpty()->end()
49
                                        ->integerNode('priority')->defaultValue(0)->end()
50
        ;
51
52
        return $treeBuilder;
53
    }
54
}
55