AddTemplatesCompilerPass::process()   A
last analyzed

Complexity

Conditions 6
Paths 6

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.0111
c 0
b 0
f 0
cc 6
nc 6
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\DoctrineMongoDBAdminBundle\DependencyInjection\Compiler;
15
16
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
17
use Symfony\Component\DependencyInjection\ContainerBuilder;
18
19
/**
20
 * @author Thomas Rabaix <[email protected]>
21
 */
22
class AddTemplatesCompilerPass implements CompilerPassInterface
23
{
24
    public function process(ContainerBuilder $container): void
25
    {
26
        foreach ($container->findTaggedServiceIds('sonata.admin') as $id => $attributes) {
27
            if (!isset($attributes[0]['manager_type']) || 'doctrine_mongodb' !== $attributes[0]['manager_type']) {
28
                continue;
29
            }
30
31
            $definition = $container->getDefinition($id);
32
            $templates = $container->getParameter('sonata_doctrine_mongodb_admin.templates');
33
34
            if (!$definition->hasMethodCall('setFormTheme')) {
35
                $definition->addMethodCall('setFormTheme', [$templates['form']]);
36
            }
37
38
            if (!$definition->hasMethodCall('setFilterTheme')) {
39
                $definition->addMethodCall('setFilterTheme', [$templates['filter']]);
40
            }
41
        }
42
    }
43
}
44