AddTreeBrowserAssetsPass   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 9 2
A addAssetsToAdminPool() 0 8 1
A addFormResources() 0 7 1
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\DoctrinePHPCRAdminBundle\DependencyInjection\Compiler;
15
16
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
17
use Symfony\Component\DependencyInjection\ContainerBuilder;
18
use Symfony\Component\DependencyInjection\Definition;
19
20
/**
21
 * Adds javascripts and stylesheets required for the TreeSelectType.
22
 *
23
 * @author Wouter de Jong <[email protected]>
24
 */
25
final class AddTreeBrowserAssetsPass implements CompilerPassInterface
26
{
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function process(ContainerBuilder $container): void
31
    {
32
        if (!$container->hasDefinition('sonata.admin.pool')) {
33
            return;
34
        }
35
36
        $this->addAssetsToAdminPool($container->findDefinition('sonata.admin.pool'));
37
        $this->addFormResources($container);
38
    }
39
40
    private function addAssetsToAdminPool(Definition $definition): void
41
    {
42
        $options = $definition->getArgument(3);
43
        $options['javascripts'][] = 'bundles/cmftreebrowser/js/cmf_tree_browser.fancytree.js';
44
        $options['stylesheets'][] = 'bundles/cmftreebrowser/css/cmf_tree_browser.fancytree.css';
45
46
        $definition->replaceArgument(3, $options);
47
    }
48
49
    private function addFormResources(ContainerBuilder $container): void
50
    {
51
        $resources = $container->getParameter('twig.form.resources');
52
        $resources[] = '@SonataDoctrinePHPCRAdmin/Form/tree_browser_fields.html.twig';
53
54
        $container->setParameter('twig.form.resources', $resources);
55
    }
56
}
57