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