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

TwigVariablesParser   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addSemanticConfig() 0 17 1
A mapConfig() 0 15 2
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