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; |
13
|
|
|
|
14
|
|
|
use Sonata\AdminBundle\DependencyInjection\AbstractSonataAdminExtension; |
15
|
|
|
use Symfony\Cmf\Bundle\ResourceBundle\DependencyInjection\Configuration as ResourceConfiguration; |
16
|
|
|
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; |
17
|
|
|
use Symfony\Component\Config\Definition\Processor; |
18
|
|
|
use Symfony\Component\Config\FileLocator; |
19
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
20
|
|
|
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; |
21
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* SonataAdminBundleExtension. |
25
|
|
|
* |
26
|
|
|
* @author Thomas Rabaix <[email protected]> |
27
|
|
|
* @author Michael Williams <[email protected]> |
28
|
|
|
* @author Nacho Martín <[email protected]> |
29
|
|
|
*/ |
30
|
|
|
class SonataDoctrinePHPCRAdminExtension extends AbstractSonataAdminExtension implements PrependExtensionInterface |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* @param array $configs An array of configuration settings |
34
|
|
|
* @param ContainerBuilder $container A ContainerBuilder instance |
35
|
|
|
*/ |
36
|
|
|
public function load(array $configs, ContainerBuilder $container) |
37
|
|
|
{ |
38
|
|
|
$defaultConfig = array( |
39
|
|
|
'templates' => array( |
40
|
|
|
'types' => array( |
41
|
|
|
'list' => array( |
42
|
|
|
'node' => 'SonataDoctrinePHPCRAdminBundle:CRUD:list_node.html.twig', |
43
|
|
|
), |
44
|
|
|
'show' => array( |
45
|
|
|
'doctrine_phpcr_many_to_many' => 'SonataDoctrinePHPCRAdminBundle:CRUD:show_phpcr_many_to_many.html.twig', |
46
|
|
|
'doctrine_phpcr_many_to_one' => 'SonataDoctrinePHPCRAdminBundle:CRUD:show_phpcr_many_to_one.html.twig', |
47
|
|
|
'doctrine_phpcr_one_to_many' => 'SonataDoctrinePHPCRAdminBundle:CRUD:show_phpcr_one_to_many.html.twig', |
48
|
|
|
'doctrine_phpcr_one_to_one' => 'SonataDoctrinePHPCRAdminBundle:CRUD:show_phpcr_one_to_one.html.twig', |
49
|
|
|
), |
50
|
|
|
), |
51
|
|
|
), |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
$configs = $this->fixTemplatesConfiguration($configs, $container, $defaultConfig); |
55
|
|
|
|
56
|
|
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
57
|
|
|
$loader->load('doctrine_phpcr.xml'); |
58
|
|
|
$loader->load('doctrine_phpcr_filter_types.xml'); |
59
|
|
|
$loader->load('doctrine_phpcr_form_types.xml'); |
60
|
|
|
$loader->load('form.xml'); |
61
|
|
|
$loader->load('route.xml'); |
62
|
|
|
$loader->load('twig.xml'); |
63
|
|
|
$loader->load('block.xml'); |
64
|
|
|
$loader->load('tree.xml'); |
65
|
|
|
$loader->load('autocomplete.xml'); |
66
|
|
|
|
67
|
|
|
$configuration = new Configuration(); |
68
|
|
|
$processor = new Processor(); |
69
|
|
|
$config = $processor->processConfiguration($configuration, $configs); |
70
|
|
|
|
71
|
|
|
$pool = $container->getDefinition('sonata.admin.manager.doctrine_phpcr'); |
72
|
|
|
$pool->addMethodCall('__hack_doctrine_phpcr__', $config); |
73
|
|
|
|
74
|
|
|
$container->getDefinition('sonata.admin.builder.doctrine_phpcr_list') |
75
|
|
|
->replaceArgument(1, $config['templates']['types']['list']); |
76
|
|
|
|
77
|
|
|
$container->getDefinition('sonata.admin.builder.doctrine_phpcr_show') |
78
|
|
|
->replaceArgument(1, $config['templates']['types']['show']); |
79
|
|
|
|
80
|
|
|
if ($this->isConfigEnabled($container, $config['document_tree'])) { |
81
|
|
|
$this->loadDocumentTree($config['document_tree'], $container); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function getNamespace() |
86
|
|
|
{ |
87
|
|
|
return 'http://sonata-project.org/schema/dic/doctrine_phpcr_admin'; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* {@inheritdoc} |
92
|
|
|
*/ |
93
|
|
|
public function prepend(ContainerBuilder $container) |
94
|
|
|
{ |
95
|
|
|
// process the configuration of CmfResourceBundle |
96
|
|
|
$configs = $container->getExtensionConfig('sonata_doctrine_phpcr_admin'); |
97
|
|
|
$parameterBag = $container->getParameterBag(); |
98
|
|
|
$configs = $parameterBag->resolveValue($configs); |
99
|
|
|
$sonataConfig = $this->processConfiguration(new Configuration(), $configs); |
100
|
|
|
|
101
|
|
|
if (!$this->isConfigEnabled($container, $sonataConfig['document_tree'])) { |
102
|
|
|
return; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
$bundles = $container->getParameter('kernel.bundles'); |
106
|
|
|
if (!in_array('CmfResourceBundle', $bundles)) { |
107
|
|
|
throw new InvalidConfigurationException('CmfResourceBundle has to be enabled when using tree browser'); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
if (null !== $sonataConfig['document_tree']['repository_name']) { |
111
|
|
|
return; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
// process the configuration of CmfResourceBundle |
115
|
|
|
$configs = $container->getExtensionConfig('cmf_resource'); |
116
|
|
|
$parameterBag = $container->getParameterBag(); |
117
|
|
|
$configs = $parameterBag->resolveValue($configs); |
118
|
|
|
$config = $this->processConfiguration(new ResourceConfiguration(), $configs); |
119
|
|
|
|
120
|
|
|
$sonataConfig['document_tree']['repository_name'] = $config['default_repository']; |
121
|
|
|
|
122
|
|
|
$container->prependExtensionConfig('sonata_doctrine_phpcr_admin', $sonataConfig); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Set the document tree parameters and configuration. |
127
|
|
|
* |
128
|
|
|
* @param array $config |
129
|
|
|
* @param ContainerBuilder $container |
130
|
|
|
*/ |
131
|
|
|
private function loadDocumentTree($config, ContainerBuilder $container) |
132
|
|
|
{ |
133
|
|
|
$configuration = array( |
134
|
|
|
'routing_defaults' => $config['routing_defaults'], |
135
|
|
|
'repository_name' => $config['repository_name'], |
136
|
|
|
'sortable_by' => $config['sortable_by'], |
137
|
|
|
'move' => true, |
138
|
|
|
'reorder' => true, |
139
|
|
|
); |
140
|
|
|
|
141
|
|
|
$container->setParameter('sonata_admin_doctrine_phpcr.tree_block.configuration', $configuration); |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|