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\DoctrinePHPCRAdminBundle\DependencyInjection; |
15
|
|
|
|
16
|
|
|
use Sonata\AdminBundle\DependencyInjection\AbstractSonataAdminExtension; |
17
|
|
|
use Symfony\Component\Config\Definition\Processor; |
18
|
|
|
use Symfony\Component\Config\FileLocator; |
19
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
20
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* SonataAdminBundleExtension. |
24
|
|
|
* |
25
|
|
|
* @author Thomas Rabaix <[email protected]> |
26
|
|
|
* @author Michael Williams <[email protected]> |
27
|
|
|
* @author Nacho Martín <[email protected]> |
28
|
|
|
*/ |
29
|
|
|
class SonataDoctrinePHPCRAdminExtension extends AbstractSonataAdminExtension |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* @param array $configs An array of configuration settings |
33
|
|
|
* @param ContainerBuilder $container A ContainerBuilder instance |
34
|
|
|
*/ |
35
|
|
|
public function load(array $configs, ContainerBuilder $container): void |
36
|
|
|
{ |
37
|
|
|
$defaultConfig = [ |
38
|
|
|
'templates' => [ |
39
|
|
|
'types' => [ |
40
|
|
|
'list' => [ |
41
|
|
|
'node' => '@SonataDoctrinePHPCRAdmin/CRUD/list_node.html.twig', |
42
|
|
|
], |
43
|
|
|
'show' => [ |
44
|
|
|
'doctrine_phpcr_many_to_many' => '@SonataAdmin/CRUD/Association/show_many_to_many.html.twig', |
45
|
|
|
'doctrine_phpcr_many_to_one' => '@SonataAdmin/CRUD/Association/show_many_to_one.html.twig', |
46
|
|
|
'doctrine_phpcr_one_to_many' => '@SonataAdmin/CRUD/Association/show_one_to_many.html.twig', |
47
|
|
|
'doctrine_phpcr_one_to_one' => '@SonataAdmin/CRUD/Association/show_one_to_one.html.twig', |
48
|
|
|
], |
49
|
|
|
], |
50
|
|
|
], |
51
|
|
|
]; |
52
|
|
|
|
53
|
|
|
$configs = $this->fixTemplatesConfiguration($configs, $container, $defaultConfig); |
54
|
|
|
|
55
|
|
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
56
|
|
|
$loader->load('doctrine_phpcr.xml'); |
57
|
|
|
$loader->load('doctrine_phpcr_filter_types.xml'); |
58
|
|
|
$loader->load('doctrine_phpcr_form_types.xml'); |
59
|
|
|
$loader->load('form.xml'); |
60
|
|
|
$loader->load('route.xml'); |
61
|
|
|
$loader->load('twig.xml'); |
62
|
|
|
$loader->load('block.xml'); |
63
|
|
|
$loader->load('tree.xml'); |
64
|
|
|
$loader->load('autocomplete.xml'); |
65
|
|
|
|
66
|
|
|
$configuration = new Configuration(); |
67
|
|
|
$processor = new Processor(); |
68
|
|
|
$config = $processor->processConfiguration($configuration, $configs); |
69
|
|
|
|
70
|
|
|
$pool = $container->getDefinition('sonata.admin.manager.doctrine_phpcr'); |
71
|
|
|
$pool->addMethodCall('__hack_doctrine_phpcr__', $config); |
72
|
|
|
|
73
|
|
|
$container->getDefinition('sonata.admin.builder.doctrine_phpcr_list') |
74
|
|
|
->replaceArgument(1, $config['templates']['types']['list']); |
75
|
|
|
|
76
|
|
|
$container->getDefinition('sonata.admin.builder.doctrine_phpcr_show') |
77
|
|
|
->replaceArgument(1, $config['templates']['types']['show']); |
78
|
|
|
|
79
|
|
|
if ($this->isConfigEnabled($container, $config['document_tree'])) { |
80
|
|
|
$this->loadDocumentTree($config['document_tree'], $container); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function getNamespace() |
85
|
|
|
{ |
86
|
|
|
return 'http://sonata-project.org/schema/dic/doctrine_phpcr_admin'; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Set the document tree parameters and configuration. |
91
|
|
|
* |
92
|
|
|
* @param array $config |
93
|
|
|
*/ |
94
|
|
|
private function loadDocumentTree($config, ContainerBuilder $container): void |
95
|
|
|
{ |
96
|
|
|
$configuration = [ |
97
|
|
|
'routing_defaults' => $config['routing_defaults'], |
98
|
|
|
'repository_name' => $config['repository_name'], |
99
|
|
|
'sortable_by' => $config['sortable_by'], |
100
|
|
|
'move' => true, |
101
|
|
|
'reorder' => true, |
102
|
|
|
]; |
103
|
|
|
|
104
|
|
|
$container->setParameter('sonata_admin_doctrine_phpcr.tree_block.configuration', $configuration); |
105
|
|
|
|
106
|
|
|
foreach ($configuration as $key => $value) { |
107
|
|
|
$container->setParameter('sonata_admin_doctrine_phpcr.tree_block.'.$key, $value); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|