Completed
Push — ezp-31088-refactor-content-mod... ( ab3ba3...3726c8 )
by
unknown
14:09
created

TwigVariablesParser::mapConfig()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 3
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
declare(strict_types=1);
8
9
namespace eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\Parser;
10
11
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\AbstractParser;
12
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware\ContextualizerInterface;
13
use Symfony\Component\Config\Definition\Builder\NodeBuilder;
14
15
final class TwigVariablesParser extends AbstractParser
16
{
17
    public function addSemanticConfig(NodeBuilder $nodeBuilder)
18
    {
19
        $nodeBuilder
20
            ->arrayNode('twig_variables')
21
                ->info('Contextual Twig variables.')
22
                ->useAttributeAsKey('name')
23
                ->normalizeKeys(false)
24
                ->example([
25
                    'some' => 'variable',
26
                    'nested' => [
27
                        'some' => 'variable',
28
                        'other' => 123,
29
                    ],
30
                ])
31
                ->prototype('variable')->end()
32
            ->end();
33
    }
34
35
    public function mapConfig(
36
        array &$scopeSettings,
37
        $currentScope,
38
        ContextualizerInterface $contextualizer
39
    ) {
40
        if (!empty($scopeSettings['twig_variables'])) {
41
            $settings = $scopeSettings['twig_variables'];
42
43
            $contextualizer->setContextualParameter(
44
                'twig_variables',
45
                $currentScope,
46
                $settings
47
            );
48
        }
49
    }
50
}
51