-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
AbstractSonataAdminExtension.php
143 lines (133 loc) · 9.57 KB
/
AbstractSonataAdminExtension.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sonata\AdminBundle\DependencyInjection;
use Sonata\AdminBundle\FieldDescription\FieldDescriptionInterface;
use Sonata\AdminBundle\Templating\TemplateRegistry;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
/**
* @author Thomas Rabaix <[email protected]>
*/
abstract class AbstractSonataAdminExtension extends Extension
{
/**
* @return array
*/
protected function fixTemplatesConfiguration(
array $configs,
ContainerBuilder $container,
array $defaultSonataDoctrineConfig = []
) {
$defaultConfig = [
'templates' => [
'types' => [
'list' => [
FieldDescriptionInterface::TYPE_ARRAY => '@SonataAdmin/CRUD/list_array.html.twig',
FieldDescriptionInterface::TYPE_BOOLEAN => '@SonataAdmin/CRUD/list_boolean.html.twig',
FieldDescriptionInterface::TYPE_DATE => '@SonataAdmin/CRUD/list_date.html.twig',
FieldDescriptionInterface::TYPE_TIME => '@SonataAdmin/CRUD/list_time.html.twig',
FieldDescriptionInterface::TYPE_DATETIME => '@SonataAdmin/CRUD/list_datetime.html.twig',
/* NEXT_MAJOR: Remove this line. */
TemplateRegistry::TYPE_TEXT => '@SonataAdmin/CRUD/list_string.html.twig',
FieldDescriptionInterface::TYPE_TEXTAREA => '@SonataAdmin/CRUD/list_string.html.twig',
FieldDescriptionInterface::TYPE_EMAIL => '@SonataAdmin/CRUD/list_email.html.twig',
FieldDescriptionInterface::TYPE_TRANS => '@SonataAdmin/CRUD/list_trans.html.twig',
FieldDescriptionInterface::TYPE_STRING => '@SonataAdmin/CRUD/list_string.html.twig',
/* NEXT_MAJOR: Remove this line. */
TemplateRegistry::TYPE_SMALLINT => '@SonataAdmin/CRUD/list_string.html.twig',
/* NEXT_MAJOR: Remove this line. */
TemplateRegistry::TYPE_BIGINT => '@SonataAdmin/CRUD/list_string.html.twig',
FieldDescriptionInterface::TYPE_INTEGER => '@SonataAdmin/CRUD/list_string.html.twig',
/* NEXT_MAJOR: Remove this line. */
TemplateRegistry::TYPE_DECIMAL => '@SonataAdmin/CRUD/list_string.html.twig',
FieldDescriptionInterface::TYPE_FLOAT => '@SonataAdmin/CRUD/list_string.html.twig',
FieldDescriptionInterface::TYPE_IDENTIFIER => '@SonataAdmin/CRUD/list_string.html.twig',
FieldDescriptionInterface::TYPE_CURRENCY => '@SonataAdmin/CRUD/list_currency.html.twig',
FieldDescriptionInterface::TYPE_PERCENT => '@SonataAdmin/CRUD/list_percent.html.twig',
FieldDescriptionInterface::TYPE_CHOICE => '@SonataAdmin/CRUD/list_choice.html.twig',
FieldDescriptionInterface::TYPE_URL => '@SonataAdmin/CRUD/list_url.html.twig',
FieldDescriptionInterface::TYPE_HTML => '@SonataAdmin/CRUD/list_html.html.twig',
FieldDescriptionInterface::TYPE_MANY_TO_MANY => '@SonataAdmin/CRUD/Association/list_many_to_many.html.twig',
FieldDescriptionInterface::TYPE_MANY_TO_ONE => '@SonataAdmin/CRUD/Association/list_many_to_one.html.twig',
FieldDescriptionInterface::TYPE_ONE_TO_MANY => '@SonataAdmin/CRUD/Association/list_one_to_many.html.twig',
FieldDescriptionInterface::TYPE_ONE_TO_ONE => '@SonataAdmin/CRUD/Association/list_one_to_one.html.twig',
],
'show' => [
FieldDescriptionInterface::TYPE_ARRAY => '@SonataAdmin/CRUD/show_array.html.twig',
FieldDescriptionInterface::TYPE_BOOLEAN => '@SonataAdmin/CRUD/show_boolean.html.twig',
FieldDescriptionInterface::TYPE_DATE => '@SonataAdmin/CRUD/show_date.html.twig',
FieldDescriptionInterface::TYPE_TIME => '@SonataAdmin/CRUD/show_time.html.twig',
FieldDescriptionInterface::TYPE_DATETIME => '@SonataAdmin/CRUD/show_datetime.html.twig',
/* NEXT_MAJOR: Remove this line. */
TemplateRegistry::TYPE_TEXT => '@SonataAdmin/CRUD/base_show_field.html.twig',
FieldDescriptionInterface::TYPE_EMAIL => '@SonataAdmin/CRUD/show_email.html.twig',
FieldDescriptionInterface::TYPE_TRANS => '@SonataAdmin/CRUD/show_trans.html.twig',
FieldDescriptionInterface::TYPE_STRING => '@SonataAdmin/CRUD/base_show_field.html.twig',
/* NEXT_MAJOR: Remove this line. */
TemplateRegistry::TYPE_SMALLINT => '@SonataAdmin/CRUD/base_show_field.html.twig',
/* NEXT_MAJOR: Remove this line. */
TemplateRegistry::TYPE_BIGINT => '@SonataAdmin/CRUD/base_show_field.html.twig',
FieldDescriptionInterface::TYPE_INTEGER => '@SonataAdmin/CRUD/base_show_field.html.twig',
/* NEXT_MAJOR: Remove this line. */
TemplateRegistry::TYPE_DECIMAL => '@SonataAdmin/CRUD/base_show_field.html.twig',
FieldDescriptionInterface::TYPE_FLOAT => '@SonataAdmin/CRUD/base_show_field.html.twig',
FieldDescriptionInterface::TYPE_CURRENCY => '@SonataAdmin/CRUD/show_currency.html.twig',
FieldDescriptionInterface::TYPE_PERCENT => '@SonataAdmin/CRUD/show_percent.html.twig',
FieldDescriptionInterface::TYPE_CHOICE => '@SonataAdmin/CRUD/show_choice.html.twig',
FieldDescriptionInterface::TYPE_URL => '@SonataAdmin/CRUD/show_url.html.twig',
FieldDescriptionInterface::TYPE_HTML => '@SonataAdmin/CRUD/show_html.html.twig',
FieldDescriptionInterface::TYPE_MANY_TO_MANY => '@SonataAdmin/CRUD/Association/show_many_to_many.html.twig',
FieldDescriptionInterface::TYPE_MANY_TO_ONE => '@SonataAdmin/CRUD/Association/show_many_to_one.html.twig',
FieldDescriptionInterface::TYPE_ONE_TO_MANY => '@SonataAdmin/CRUD/Association/show_one_to_many.html.twig',
FieldDescriptionInterface::TYPE_ONE_TO_ONE => '@SonataAdmin/CRUD/Association/show_one_to_one.html.twig',
],
],
],
];
// let's add some magic, only overwrite template if the SonataIntlBundle is enabled
$bundles = $container->getParameter('kernel.bundles');
if (isset($bundles['SonataIntlBundle'])) {
$defaultConfig['templates']['types']['list'] = array_merge($defaultConfig['templates']['types']['list'], [
FieldDescriptionInterface::TYPE_DATE => '@SonataIntl/CRUD/list_date.html.twig',
FieldDescriptionInterface::TYPE_DATETIME => '@SonataIntl/CRUD/list_datetime.html.twig',
/* NEXT_MAJOR: Remove this line. */
TemplateRegistry::TYPE_SMALLINT => '@SonataIntl/CRUD/list_decimal.html.twig',
/* NEXT_MAJOR: Remove this line. */
TemplateRegistry::TYPE_BIGINT => '@SonataIntl/CRUD/list_decimal.html.twig',
FieldDescriptionInterface::TYPE_INTEGER => '@SonataIntl/CRUD/list_decimal.html.twig',
/* NEXT_MAJOR: Remove this line. */
TemplateRegistry::TYPE_DECIMAL => '@SonataIntl/CRUD/list_decimal.html.twig',
FieldDescriptionInterface::TYPE_FLOAT => '@SonataIntl/CRUD/list_decimal.html.twig',
FieldDescriptionInterface::TYPE_CURRENCY => '@SonataIntl/CRUD/list_currency.html.twig',
FieldDescriptionInterface::TYPE_PERCENT => '@SonataIntl/CRUD/list_percent.html.twig',
]);
$defaultConfig['templates']['types']['show'] = array_merge($defaultConfig['templates']['types']['show'], [
FieldDescriptionInterface::TYPE_DATE => '@SonataIntl/CRUD/show_date.html.twig',
FieldDescriptionInterface::TYPE_DATETIME => '@SonataIntl/CRUD/show_datetime.html.twig',
/* NEXT_MAJOR: Remove this line. */
TemplateRegistry::TYPE_SMALLINT => '@SonataIntl/CRUD/show_decimal.html.twig',
/* NEXT_MAJOR: Remove this line. */
TemplateRegistry::TYPE_BIGINT => '@SonataIntl/CRUD/show_decimal.html.twig',
FieldDescriptionInterface::TYPE_INTEGER => '@SonataIntl/CRUD/show_decimal.html.twig',
/* NEXT_MAJOR: Remove this line. */
TemplateRegistry::TYPE_DECIMAL => '@SonataIntl/CRUD/show_decimal.html.twig',
FieldDescriptionInterface::TYPE_FLOAT => '@SonataIntl/CRUD/show_decimal.html.twig',
FieldDescriptionInterface::TYPE_CURRENCY => '@SonataIntl/CRUD/show_currency.html.twig',
FieldDescriptionInterface::TYPE_PERCENT => '@SonataIntl/CRUD/show_percent.html.twig',
]);
}
if (!empty($defaultSonataDoctrineConfig)) {
$defaultConfig = array_merge_recursive($defaultConfig, $defaultSonataDoctrineConfig);
}
array_unshift($configs, $defaultConfig);
return $configs;
}
}