AddTreeBrowserAssetsPass::addAssetsToAdminPool()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 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