This repository has been archived by the owner on Jul 22, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 93
/
AddTemplatesCompilerPass.php
78 lines (63 loc) · 2.3 KB
/
AddTemplatesCompilerPass.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sonata\DoctrinePHPCRAdminBundle\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
/**
* @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
* @author Nacho Martín <nitram.ohcan@gmail.com>
*/
class AddTemplatesCompilerPass implements CompilerPassInterface
{
/**
* @param ContainerBuilder $container
*/
public function process(ContainerBuilder $container)
{
$settings = $this->fixSettings($container);
foreach ($container->findTaggedServiceIds('sonata.admin') as $id => $attributes) {
if (!isset($attributes[0]['manager_type']) || 'doctrine_phpcr' !== $attributes[0]['manager_type']) {
continue;
}
$definition = $container->getDefinition($id);
if (!$definition->hasMethodCall('setFormTheme')) {
$definition->addMethodCall('setFormTheme', [$settings['templates']['form']]);
}
if (!$definition->hasMethodCall('setFilterTheme')) {
$definition->addMethodCall('setFilterTheme', [$settings['templates']['filter']]);
}
$definition->addMethodCall('setTemplate', ['pager_results', $settings['templates']['pager_results']]);
}
}
/**
* @param ContainerBuilder $container
*
* @return bool
*/
protected function fixSettings(ContainerBuilder $container)
{
$pool = $container->getDefinition('sonata.admin.manager.doctrine_phpcr');
// @todo not very clean but don't know how to do that for now
$settings = false;
$methods = $pool->getMethodCalls();
foreach ($methods as $pos => $calls) {
if ('__hack_doctrine_phpcr__' === $calls[0]) {
$settings = $calls[1];
break;
}
}
if ($settings) {
unset($methods[$pos]);
}
$pool->setMethodCalls($methods);
return $settings;
}
}