Completed
Pull Request — 1.x (#473)
by Maximilian
02:36 queued 52s
created

AddTreeBrowserAssetsPass::addFormResources()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 7
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Sonata Project package.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
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
namespace Sonata\DoctrinePHPCRAdminBundle\DependencyInjection\Compiler;
13
14
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\DependencyInjection\Definition;
17
18
/**
19
 * Adds javascripts and stylesheets required for the TreeSelectType.
20
 *
21
 * @author Wouter de Jong <[email protected]>
22
 */
23
final class AddTreeBrowserAssetsPass implements CompilerPassInterface
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function process(ContainerBuilder $container)
29
    {
30
        if (!$container->hasDefinition('sonata.admin.pool')) {
31
            return;
32
        }
33
34
        $this->addAssetsToAdminPool($container->findDefinition('sonata.admin.pool'));
35
        $this->addFormResources($container);
36
    }
37
38
    private function addAssetsToAdminPool(Definition $definition)
39
    {
40
        $options = $definition->getArgument(3);
41
        $options['javascripts'][] = 'bundles/cmftreebrowser/js/cmf_tree_browser.fancytree.js';
42
        $options['stylesheets'][] = 'bundles/cmftreebrowser/css/cmf_tree_browser.fancytree.css';
43
44
        $definition->replaceArgument(3, $options);
45
    }
46
47
    private function addFormResources(ContainerBuilder $container)
48
    {
49
        $resources = $container->getParameter('twig.form.resources');
50
        $resources[] = 'SonataDoctrinePHPCRAdminBundle:Form:tree_browser_fields.html.twig';
51
52
        $container->setParameter('twig.form.resources', $resources);
53
    }
54
}
55