-
-
Notifications
You must be signed in to change notification settings - Fork 205
Expand file tree
/
Copy pathConfiguration.php
More file actions
290 lines (263 loc) · 12.7 KB
/
Configuration.php
File metadata and controls
290 lines (263 loc) · 12.7 KB
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
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sonata\PageBundle\DependencyInjection;
use Sonata\PageBundle\Model\Template;
use Sonata\PageBundle\Template\Matrix\Parser;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
/**
* @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
*/
final class Configuration implements ConfigurationInterface
{
/**
* @return TreeBuilder<'array'>
*/
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('sonata_page');
$rootNode = $treeBuilder->getRootNode();
$routerAutoRegisterInfo = <<<'EOF'
Automatically add 'sonata.page.router' service to the index of 'cmf_routing.router' chain router
Examples:
enabled: true Enable auto-registration
priority: 150 The priority
EOF;
$ignoreRoutePatternsInfo = <<<'EOF'
(.*)admin(.*) ignore admin route, i.e. route containing 'admin'
^_(.*) ignore Symfony routes
EOF;
$ignoreUriPatternsInfo = <<<'EOF'
admin(.*) ignore admin route, i.e. route containing 'admin'
EOF;
$pageDefaultsInfo = <<<'EOF'
Example:
homepage: { decorate: false } disable decoration for 'homepage', key is a page route
EOF;
$catchExceptionsInfo = <<<'EOF'
Manage the HTTP errors
Examples:
not_found: [404] render 404 page with "not_found" key (name generated: _page_internal_error_not_found)
fatal: [500] render 500 page with "fatal" key (name generated: _page_internal_error_fatal)
EOF;
$directPublicationInfo = <<<'EOF'
Generates a snapshot when a page is saved from the admin.
You can use %kernel.debug%, if you want to publish in dev mode, but not in prod.
EOF;
$rootNode
->children()
->scalarNode('skip_redirection')
->info('To skip asking Editor to redirect')
->defaultFalse()
->end()
->scalarNode('hide_disabled_blocks')
->defaultFalse()
->end()
->scalarNode('use_streamed_response')
->info('Set the value to false in debug mode or if the reverse proxy does not handle streamed response')
->defaultFalse()
->end()
->scalarNode('multisite')
->info('For more information, see https://docs.sonata-project.org/projects/SonataPageBundle/en/4.x/reference/multisite/')
->isRequired()
->validate()
->ifNotInArray(['host', 'host_by_locale', 'host_with_path', 'host_with_path_by_locale'])
->thenInvalid('Invalid multisite configuration %s. For more information, see https://docs.sonata-project.org/projects/SonataPageBundle/en/4.x/reference/multisite/')
->end()
->end()
->arrayNode('router_auto_register')
->info($routerAutoRegisterInfo)
->addDefaultsIfNotSet()
->children()
->booleanNode('enabled')
->defaultValue(false)
->end()
->integerNode('priority')
->defaultValue(150)
->end()
->end()
->end()
->arrayNode('ignore_route_patterns')
->info($ignoreRoutePatternsInfo)
->defaultValue([
'(.*)admin(.*)',
'^_(.*)',
])
->prototype('scalar')->end()
->end()
->arrayNode('ignore_routes')
->defaultValue([])
->prototype('scalar')->end()
->end()
->arrayNode('ignore_uri_patterns')
->info($ignoreUriPatternsInfo)
->defaultValue([
'admin(.*)',
])
->prototype('scalar')->end()
->end()
->scalarNode('default_page_service')
->defaultValue('sonata.page.service.default')
->end()
->scalarNode('default_template')
->info('Template key from templates section, used as default for pages')
->isRequired()
->end()
->arrayNode('templates')
->isRequired()
->useAttributeAsKey('id')
->prototype('array')
->children()
->scalarNode('name')->end()
->scalarNode('path')->end()
->scalarNode('inherits_containers')->end()
->arrayNode('containers')
->requiresAtLeastOneElement()
->useAttributeAsKey('id')
->prototype('array')
->children()
->scalarNode('name')->end()
->booleanNode('shared')
->defaultValue(false)
->end()
->scalarNode('type')
->defaultValue(Template::TYPE_STATIC)
->end()
->arrayNode('blocks')
->prototype('scalar')->end()
->end()
->end()
->end()
->end()
->arrayNode('matrix')
->children()
->scalarNode('layout')
->isRequired()
->end()
->arrayNode('mapping')
->isRequired()
->requiresAtLeastOneElement()
->prototype('scalar')->isRequired()->end()
->end()
->end()
->validate()
->always()
->then(static fn (array $matrix) => Parser::parse($matrix['layout'], $matrix['mapping']))
->end()
->end()
->end()
->end()
->validate()
->always()
->then(static function (array $templates): array {
foreach ($templates as $id => &$template) {
if (0 === \count($template['containers'])) {
continue;
}
if (isset($template['inherits_containers'])) {
$inherits = $template['inherits_containers'];
if (!isset($templates[$inherits])) {
throw new InvalidConfigurationException(
\sprintf('Template "%s" cannot inherit containers from undefined template "%s"', $id, $inherits)
);
}
$template['containers'] = array_merge($templates[$inherits]['containers'], $template['containers']);
}
foreach ($template['containers'] as $containerKey => $container) {
if (!isset($template['matrix'][$containerKey])) {
throw new InvalidConfigurationException(
\sprintf('No area defined in matrix for template container "%s"', $containerKey)
);
}
}
foreach ($template['matrix'] as $containerKey => $config) {
if (!isset($template['containers'][$containerKey])) {
throw new InvalidConfigurationException(
\sprintf('No container defined for matrix area "%s"', $containerKey)
);
}
$template['containers'][$containerKey]['placement'] = $config;
}
unset($template['inherits_containers'], $template['matrix']);
}
return $templates;
})
->end()
->end()
->arrayNode('templates_admin')
->addDefaultsIfNotSet()
->children()
->scalarNode('list')
->defaultValue('@SonataPage/PageAdmin/list.html.twig')
->cannotBeEmpty()
->end()
->scalarNode('tree')
->defaultValue('@SonataPage/PageAdmin/tree.html.twig')
->cannotBeEmpty()
->end()
->scalarNode('compose')
->defaultValue('@SonataPage/PageAdmin/compose.html.twig')
->cannotBeEmpty()
->end()
->scalarNode('compose_container_show')
->defaultValue('@SonataPage/PageAdmin/compose_container_show.html.twig')
->cannotBeEmpty()
->end()
->scalarNode('select_site')
->defaultValue('@SonataPage/PageAdmin/select_site.html.twig')
->cannotBeEmpty()
->end()
->end()
->end()
->arrayNode('page_defaults')
->info($pageDefaultsInfo)
->useAttributeAsKey('id')
->prototype('array')
->children()
->booleanNode('decorate')
->defaultValue(true)
->end()
->booleanNode('enabled')
->defaultValue(true)
->end()
->end()
->end()
->end()
->arrayNode('catch_exceptions')
->info($catchExceptionsInfo)
->useAttributeAsKey('id')
->prototype('variable')->isRequired()->end()
->end()
->arrayNode('class')
->addDefaultsIfNotSet()
->children()
->scalarNode('page')
->defaultValue('App\\Entity\\SonataPagePage')
->end()
->scalarNode('snapshot')
->defaultValue('App\\Entity\\SonataPageSnapshot')
->end()
->scalarNode('block')
->defaultValue('App\\Entity\\SonataPageBlock')
->end()
->scalarNode('site')
->defaultValue('App\\Entity\\SonataPageSite')
->end()
->end()
->end()
->booleanNode('direct_publication')
->info($directPublicationInfo)
->defaultValue(false)
->end();
return $treeBuilder;
}
}