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\DoctrineORMAdminBundle\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
|
|
|
* @author Thomas Rabaix <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class AddTemplatesCompilerPass implements CompilerPassInterface |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* {@inheritdoc} |
25
|
|
|
*/ |
26
|
|
|
public function process(ContainerBuilder $container) |
27
|
|
|
{ |
28
|
|
|
$overwrite = $container->getParameter('sonata.admin.configuration.admin_services'); |
29
|
|
|
$templates = $container->getParameter('sonata_doctrine_orm_admin.templates'); |
30
|
|
|
|
31
|
|
|
foreach ($container->findTaggedServiceIds('sonata.admin') as $id => $attributes) { |
32
|
|
|
if (!isset($attributes[0]['manager_type']) || $attributes[0]['manager_type'] != 'orm') { |
33
|
|
|
continue; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
$definition = $container->getDefinition($id); |
37
|
|
|
|
38
|
|
|
if (!$definition->hasMethodCall('setFormTheme')) { |
39
|
|
|
$definition->addMethodCall('setFormTheme', array($templates['form'])); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
if (isset($overwrite[$id]['templates']['form'])) { |
43
|
|
|
$this->mergeMethodCall($definition, 'setFormTheme', $overwrite[$id]['templates']['form']); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
if (!$definition->hasMethodCall('setFilterTheme')) { |
47
|
|
|
$definition->addMethodCall('setFilterTheme', array($templates['filter'])); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
if (isset($overwrite[$id]['templates']['filter'])) { |
51
|
|
|
$this->mergeMethodCall($definition, 'setFilterTheme', $overwrite[$id]['templates']['filter']); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param Definition $definition |
58
|
|
|
* @param string $name |
59
|
|
|
* @param mixed $value |
60
|
|
|
*/ |
61
|
|
|
public function mergeMethodCall(Definition $definition, $name, $value) |
62
|
|
|
{ |
63
|
|
|
$methodCalls = $definition->getMethodCalls(); |
64
|
|
|
|
65
|
|
|
foreach ($methodCalls as &$calls) { |
66
|
|
|
foreach ($calls as &$call) { |
67
|
|
|
if (is_string($call)) { |
68
|
|
|
if ($call !== $name) { |
69
|
|
|
continue 2; |
70
|
|
|
} |
71
|
|
|
continue 1; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
$call = array(array_merge($call[0], $value)); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
$definition->setMethodCalls($methodCalls); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|