-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Configuration.php
374 lines (334 loc) · 17.9 KB
/
Configuration.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
<?php
/*
* This file is part of the EasyAdminBundle.
*
* (c) Javier Eguiluz <javier.eguiluz@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace JavierEguiluz\Bundle\EasyAdminBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('easy_admin');
$this->addDeprecationsSection($rootNode);
$this->addGlobalOptionsSection($rootNode);
$this->addDesignSection($rootNode);
$this->addViewsSection($rootNode);
$this->addEntitiesSection($rootNode);
return $treeBuilder;
}
private function addDeprecationsSection(ArrayNodeDefinition $rootNode)
{
$rootNode
// 'list_max_results' global option was deprecated in 1.0.8
// and replaced by 'list -> max_results'
->beforeNormalization()
->ifTrue(function ($v) { return isset($v['list_max_results']); })
->then(function ($v) {
if (!isset($v['list'])) {
$v['list'] = array();
}
// if the new option is defined, don't override it with the legacy option
if (!isset($v['list']['max_results'])) {
$v['list']['max_results'] = $v['list_max_results'];
}
unset($v['list_max_results']);
return $v;
})
->end()
// 'list_actions' global option was deprecated in 1.0.8
// and replaced by 'list -> actions'
->beforeNormalization()
->ifTrue(function ($v) { return isset($v['list_actions']); })
->then(function ($v) {
// if the new option is defined, don't override it with the legacy option
if (!isset($v['list']['actions'])) {
$v['list']['actions'] = $v['list_actions'];
}
unset($v['list_actions']);
return $v;
})
->end()
// make sure the new 'design' global option exists to simplify
// updating the deprecated 'assets -> css' and 'assets -> js' options
->beforeNormalization()
->always()
->then(function ($v) {
if (!isset($v['design'])) {
$v['design'] = array('assets' => array());
}
return $v;
})
->end()
// 'assets -> css' global option was deprecated in 1.1.0
// and replaced by 'design -> assets -> css'
->beforeNormalization()
->ifTrue(function ($v) { return isset($v['assets']['css']); })
->then(function ($v) {
// if the new option is defined, don't override it with the legacy option
if (!isset($v['design']['assets']['css'])) {
$v['design']['assets']['css'] = $v['assets']['css'];
}
unset($v['assets']['css']);
return $v;
})
->end()
// 'assets -> js' global option was deprecated in 1.1.0
// and replaced by 'design -> assets -> js'
->beforeNormalization()
->ifTrue(function ($v) { return isset($v['assets']['js']); })
->then(function ($v) {
// if the new option is defined, don't override it with the legacy option
if (!isset($v['design']['assets']['js'])) {
$v['design']['assets']['js'] = $v['assets']['js'];
}
unset($v['assets']['js']);
return $v;
})
->end()
// after updating 'assets -> css' and 'assets -> js' deprecated options,
// remove the parent 'assets' deprecated option if it's defined
->beforeNormalization()
->always()
->then(function ($v) {
if (isset($v['assets'])) {
unset($v['assets']);
}
return $v;
})
->end()
->children()
->variableNode('list_actions')
->info('DEPRECATED: use the "actions" option of the "list" view.')
->end()
->integerNode('list_max_results')
->info('DEPRECATED: use "max_results" option under the "list" global key.')
->end()
->arrayNode('assets')
->performNoDeepMerging()
->children()
->arrayNode('css')
->info('DEPRECATED: use the "design -> assets -> css" option.')
->end()
->arrayNode('js')
->info('DEPRECATED: use the "design -> assets -> js" option.')
->end()
->end()
->end()
->end()
;
}
private function addGlobalOptionsSection(ArrayNodeDefinition $rootNode)
{
$rootNode
->children()
->scalarNode('site_name')
->defaultValue('Easy Admin')
->info('The name displayed as the title of the administration zone (e.g. company name, project name).')
->end()
->arrayNode('formats')
->performNoDeepMerging()
->addDefaultsIfNotSet()
->children()
->scalarNode('date')
->defaultValue('Y-m-d')
->info('The PHP date format applied to "date" field types.')
->example('d/m/Y (see http://php.net/manual/en/function.date.php)')
->end()
->scalarNode('time')
->defaultValue('H:i:s')
->info('The PHP time format applied to "time" field types.')
->example('h:i a (see http://php.net/date)')
->end()
->scalarNode('datetime')
->defaultValue('F j, Y H:i')
->info('The PHP date/time format applied to "datetime" field types.')
->example('l, F jS Y / h:i (see http://php.net/date)')
->end()
->scalarNode('number')
->info('The sprintf-compatible format applied to numeric values.')
->example('%.2d (see http://php.net/sprintf)')
->end()
->end()
->end()
->variableNode('disabled_actions')
->info('The names of the actions disabled for all backend entities.')
->defaultValue(array())
->validate()
->ifTrue(function ($v) { return false === is_array($v); })
->thenInvalid('The disabled_actions option must be an array of action names.')
->end()
->end()
->end()
;
}
private function addDesignSection(ArrayNodeDefinition $rootNode)
{
$rootNode
->children()
->arrayNode('design')
->performNoDeepMerging()
->addDefaultsIfNotSet()
->children()
// the 'theme' option is not used at the moment, but it allows us to be prepared for the future
->scalarNode('theme')
->defaultValue('default')
->info('The theme used to render the backend pages. For now this value can only be "default".')
->validate()
->ifNotInArray(array('default'))
->thenInvalid('The theme name can only be "default".')
->end()
->end()
->enumNode('color_scheme')
->values(array('dark', 'light'))
->info('The color scheme applied to the backend design (values: "dark" or "light").')
->defaultValue('dark')
->treatNullLike('dark')
->end()
->scalarNode('brand_color')
->info('The color used in the backend design to highlight important elements.')
->defaultValue('#E67E22')
->treatNullLike('#E67E22')
->validate()
// if present, remove the trailing ';' to avoid CSS issues
->ifTrue(function ($v) { return ';' === substr(trim($v), -1); })
->then(function ($v) { return trim(substr(trim($v), 0, -1)); })
->end()
->end()
->variableNode('form_theme')
->defaultValue(array('@EasyAdmin/form/bootstrap_3_horizontal_layout.html.twig'))
->treatNullLike(array('@EasyAdmin/form/bootstrap_3_horizontal_layout.html.twig'))
->info('The form theme applied to backend forms. Allowed values: "horizontal", "vertical" and a custom theme path or array of custom theme paths.')
->validate()
->ifTrue(function ($v) { return 'horizontal' === $v; })
->then(function () { return array('@EasyAdmin/form/bootstrap_3_horizontal_layout.html.twig'); })
->end()
->validate()
->ifTrue(function ($v) { return 'vertical' === $v; })
->then(function () { return array('@EasyAdmin/form/bootstrap_3_layout.html.twig'); })
->end()
->validate()
->ifString()->then(function ($v) { return array($v); })
->end()
->end()
->arrayNode('assets')
->performNoDeepMerging()
->addDefaultsIfNotSet()
->children()
->arrayNode('css')
->prototype('scalar')->end()
->info('The array of CSS assets to load in all backend pages.')
->end()
->arrayNode('js')
->prototype('scalar')->end()
->info('The array of JavaScript assets to load in all backend pages.')
->end()
->end()
->end()
->arrayNode('templates')
->info('The custom templates used to render each backend element.')
->performNoDeepMerging()
->children()
->scalarNode('layout')->info('Used to decorate the main templates (list, edit, new and show)')->end()
->scalarNode('edit')->info('Used to render the page where entities are edited')->end()
->scalarNode('list')->info('Used to render the listing page and the search results page')->end()
->scalarNode('new')->info('Used to render the page where new entities are created')->end()
->scalarNode('show')->info('Used to render the contents stored by a given entity')->end()
->scalarNode('form')->info('Used to render the form displayed in the new and edit pages')->end()
->scalarNode('flash_messages')->info('Used to render the notification area were flash messages are displayed')->end()
->scalarNode('paginator')->info('Used to render the paginator in the list page')->end()
->scalarNode('field_array')->info('Used to render array field types')->end()
->scalarNode('field_association')->info('Used to render fields that store Doctrine associations')->end()
->scalarNode('field_bigint')->info('Used to render bigint field types')->end()
->scalarNode('field_boolean')->info('Used to render boolean field types')->end()
->scalarNode('field_date')->info('Used to render date field types')->end()
->scalarNode('field_datetime')->info('Used to render datetime field types')->end()
->scalarNode('field_datetimetz')->info('Used to render datetimetz field types')->end()
->scalarNode('field_decimal')->info('Used to render decimal field types')->end()
->scalarNode('field_float')->info('Used to render float field types')->end()
->scalarNode('field_id')->info('Used to render the field called "id". This avoids formatting its value as any other regular number (with decimals and thousand separators) ')->end()
->scalarNode('field_image')->info('Used to render image field types (a special type that displays the image contents)')->end()
->scalarNode('field_integer')->info('Used to render integer field types')->end()
->scalarNode('field_simple_array')->info('Used to render simple array field types')->end()
->scalarNode('field_smallint')->info('Used to render smallint field types')->end()
->scalarNode('field_string')->info('Used to render string field types')->end()
->scalarNode('field_text')->info('Used to render text field types')->end()
->scalarNode('field_time')->info('Used to render time field types')->end()
->scalarNode('field_toggle')->info('Used to render toggle field types (a special type that display booleans as flip switches)')->end()
->scalarNode('label_empty')->info('Used when the field to render is an empty collection')->end()
->scalarNode('label_inaccessible')->info('Used when is not possible to access the value of the field to render (there is no getter or public property)')->end()
->scalarNode('label_null')->info('Used when the value of the field to render is null')->end()
->scalarNode('label_undefined')->info('Used when any kind of error or exception happens when trying to access the value of the field to render')->end()
->end()
->end()
->end()
->end()
->end()
;
}
private function addViewsSection(ArrayNodeDefinition $rootNode)
{
$rootNode
->children()
->arrayNode('list')
->addDefaultsIfNotSet()
->children()
->arrayNode('actions')
->prototype('variable')->end()
->info('The list of actions enabled in the "list" view.')
->end()
->integerNode('max_results')
->defaultValue(15)
->info('The maximum number of items to show on listing and search pages.')
->end()
->end()
->end()
->arrayNode('edit')
->addDefaultsIfNotSet()
->children()
->arrayNode('actions')
->prototype('variable')->end()
->info('The list of actions enabled in the "edit" view.')
->end()
->end()
->end()
->arrayNode('new')
->addDefaultsIfNotSet()
->children()
->arrayNode('actions')
->prototype('variable')->end()
->info('The list of actions enabled in the "new" view.')
->end()
->end()
->end()
->arrayNode('show')
->addDefaultsIfNotSet()
->children()
->arrayNode('actions')
->prototype('variable')->end()
->info('The list of actions enabled in the "show" view.')
->end()
->end()
->end()
->end()
;
}
private function addEntitiesSection(ArrayNodeDefinition $rootNode)
{
$rootNode
->children()
->variableNode('entities')
->defaultValue(array())
->info('The list of entities to manage in the administration zone.')
->end()
->end()
;
}
}