Add site and title to translated strings
[userbundle] / DependencyInjection / Configuration.php
1 <?php declare(strict_types=1);
2
3 /*
4 * This file is part of the Rapsys UserBundle package.
5 *
6 * (c) Raphaël Gertz <symfony@rapsys.eu>
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 Rapsys\UserBundle\DependencyInjection;
13
14 use Rapsys\UserBundle\RapsysUserBundle;
15
16 use Symfony\Component\Config\Definition\Builder\TreeBuilder;
17 use Symfony\Component\Config\Definition\ConfigurationInterface;
18
19 /**
20 * {@inheritdoc}
21 *
22 * This is the class that validates and merges configuration from your app/config files.
23 *
24 * @link http://symfony.com/doc/current/cookbook/bundles/configuration.html
25 */
26 class Configuration implements ConfigurationInterface {
27 /**
28 * {@inheritdoc}
29 */
30 public function getConfigTreeBuilder(): TreeBuilder {
31 //Set tree builder
32 $treeBuilder = new TreeBuilder(RapsysUserBundle::getAlias());
33
34 //The bundle default values
35 $defaults = [
36 'class' => [
37 'civility' => 'Rapsys\\UserBundle\\Entity\\Civility',
38 'group' => 'Rapsys\\UserBundle\\Entity\\Group',
39 'user' => 'Rapsys\\UserBundle\\Entity\\User'
40 ],
41 'default' => [
42 'admin' => 'ROLE_ADMIN',
43 'civility' => 'Mister',
44 'languages' => [
45 'en_gb' => 'English'
46 ],
47 'locales' => [ 'en_gb' ],
48 'group' => [ 'Guest' ]
49 ],
50 'route' => [
51 'home' => [
52 'name' => 'rapsysuser',
53 'context' => []
54 ],
55 'confirm' => [
56 'name' => 'rapsysuser_confirm',
57 'context' => []
58 ],
59 'edit' => [
60 'name' => 'rapsysuser_edit',
61 'context' => []
62 ],
63 'index' => [
64 'name' => 'rapsysuser_index',
65 'context' => []
66 ],
67 'login' => [
68 'name' => 'rapsysuser_login',
69 'context' => []
70 ],
71 'recover' => [
72 'name' => 'rapsysuser_recover',
73 'context' => []
74 ],
75 'register' => [
76 'name' => 'rapsysuser_register',
77 'context' => []
78 ]
79 ],
80 'translate' => [ 'site', 'title' ],
81 'contact' => [
82 'address' => 'contact@example.com',
83 'name' => 'John Doe'
84 ],
85 'context' => [],
86 'edit' => [
87 'admin' => [ 'mail' => true ],
88 'field' => [],
89 'route' => [ 'home' => 'home_url' ],
90 'view' => [
91 'name' => '@RapsysUser/register.html.twig',
92 'edit' => 'Rapsys\UserBundle\Form\EditType',
93 'reset' => 'Rapsys\UserBundle\Form\ResetType',
94 'context' => [ 'title' => 'Edit' ]
95 ]
96 ],
97 'index' => [
98 'route' => [ 'home' => 'home_url' ],
99 'view' => [
100 'name' => '@RapsysUser/index.html.twig',
101 'context' => [ 'title' => 'Index' ]
102 ]
103 ],
104 'login' => [
105 'route' => [ 'home' => 'home_url', 'recover' => 'recover_url' ],
106 'view' => [
107 'name' => '@RapsysUser/login.html.twig',
108 'form' => 'Rapsys\UserBundle\Form\LoginType',
109 'context' => [ 'title' => 'Login' ]
110 ]
111 ],
112 'recover' => [
113 'route' => [ 'home' => 'home_url', 'recover' => 'recover_url' ],
114 'view' => [
115 'name' => '@RapsysUser/recover.html.twig',
116 'form' => 'Rapsys\UserBundle\Form\RecoverType',
117 'context' => [ 'title' => 'Recover' ]
118 ],
119 'mail' => [
120 'subject' => 'Welcome back to %%site%%!',
121 'html' => '@RapsysUser/mail/recover.html.twig',
122 'text' => '@RapsysUser/mail/recover.text.twig',
123 'context' => []
124 ]
125 ],
126 'register' => [
127 'admin' => [],
128 'field' => [],
129 'route' => [ 'home' => 'home_url', 'confirm' => 'confirm_url' ],
130 'view' => [
131 'name' => '@RapsysUser/register.html.twig',
132 'form' => 'Rapsys\UserBundle\Form\RegisterType',
133 'context' => [ 'title' => 'Register' ]
134 ],
135 'mail' => [
136 'subject' => 'Welcome to %%site%%!',
137 'html' => '@RapsysUser/mail/register.html.twig',
138 'text' => '@RapsysUser/mail/register.text.twig',
139 'context' => []
140 ]
141 ]
142 ];
143
144 /**
145 * Defines parameters allowed to configure the bundle
146 *
147 * @link https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
148 * @link http://symfony.com/doc/current/components/config/definition.html
149 * @link https://github.com/symfony/assetic-bundle/blob/master/DependencyInjection/Configuration.php#L63
150 *
151 * @see php bin/console config:dump-reference rapsysuser to dump default config
152 * @see php bin/console debug:config rapsysuser to dump config
153 */
154 $treeBuilder
155 //Parameters
156 ->getRootNode()
157 ->addDefaultsIfNotSet()
158 ->children()
159 ->arrayNode('class')
160 ->addDefaultsIfNotSet()
161 #XXX: ignoreExtraKeys(bool $remove = true)
162 ->ignoreExtraKeys(false)
163 ->children()
164 ->scalarNode('civility')->cannotBeEmpty()->defaultValue($defaults['class']['civility'])->end()
165 ->scalarNode('group')->cannotBeEmpty()->defaultValue($defaults['class']['group'])->end()
166 ->scalarNode('user')->cannotBeEmpty()->defaultValue($defaults['class']['user'])->end()
167 ->end()
168 ->end()
169 ->arrayNode('default')
170 ->addDefaultsIfNotSet()
171 #XXX: ignoreExtraKeys(bool $remove = true)
172 ->ignoreExtraKeys(false)
173 ->children()
174 ->scalarNode('admin')->cannotBeEmpty()->defaultValue($defaults['default']['admin'])->end()
175 ->scalarNode('civility')->cannotBeEmpty()->defaultValue($defaults['default']['civility'])->end()
176 #TODO: see if we can't prevent key normalisation with ->normalizeKeys(false)
177 ->arrayNode('languages')
178 ->treatNullLike([])
179 ->defaultValue($defaults['default']['languages'])
180 ->scalarPrototype()->end()
181 ->end()
182 #TODO: see if we can't prevent key normalisation with ->normalizeKeys(false)
183 ->arrayNode('locales')
184 ->treatNullLike([])
185 ->defaultValue($defaults['default']['locales'])
186 ->scalarPrototype()->end()
187 ->end()
188 ->arrayNode('group')
189 ->treatNullLike([])
190 ->defaultValue($defaults['default']['group'])
191 ->scalarPrototype()->end()
192 ->end()
193 ->end()
194 ->end()
195 ->arrayNode('route')
196 ->addDefaultsIfNotSet()
197 ->children()
198 ->arrayNode('confirm')
199 ->addDefaultsIfNotSet()
200 ->children()
201 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['route']['confirm']['name'])->end()
202 ->arrayNode('context')
203 ->treatNullLike([])
204 ->defaultValue($defaults['route']['confirm']['context'])
205 ->scalarPrototype()->end()
206 ->end()
207 ->end()
208 ->end()
209 ->arrayNode('edit')
210 ->addDefaultsIfNotSet()
211 ->children()
212 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['route']['edit']['name'])->end()
213 ->arrayNode('context')
214 ->treatNullLike([])
215 ->defaultValue($defaults['route']['edit']['context'])
216 ->scalarPrototype()->end()
217 ->end()
218 ->end()
219 ->end()
220 ->arrayNode('home')
221 ->addDefaultsIfNotSet()
222 ->children()
223 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['route']['home']['name'])->end()
224 ->arrayNode('context')
225 ->treatNullLike([])
226 ->defaultValue($defaults['route']['home']['context'])
227 ->scalarPrototype()->end()
228 ->end()
229 ->end()
230 ->end()
231 ->arrayNode('index')
232 ->addDefaultsIfNotSet()
233 ->children()
234 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['route']['index']['name'])->end()
235 ->arrayNode('context')
236 ->treatNullLike([])
237 ->defaultValue($defaults['route']['index']['context'])
238 ->scalarPrototype()->end()
239 ->end()
240 ->end()
241 ->end()
242 ->arrayNode('login')
243 ->addDefaultsIfNotSet()
244 ->children()
245 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['route']['login']['name'])->end()
246 ->arrayNode('context')
247 ->treatNullLike([])
248 ->defaultValue($defaults['route']['login']['context'])
249 ->scalarPrototype()->end()
250 ->end()
251 ->end()
252 ->end()
253 ->arrayNode('recover')
254 ->addDefaultsIfNotSet()
255 ->children()
256 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['route']['recover']['name'])->end()
257 ->arrayNode('context')
258 ->treatNullLike([])
259 ->defaultValue($defaults['route']['recover']['context'])
260 ->scalarPrototype()->end()
261 ->end()
262 ->end()
263 ->end()
264 ->arrayNode('register')
265 ->addDefaultsIfNotSet()
266 ->children()
267 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['route']['register']['name'])->end()
268 ->arrayNode('context')
269 ->treatNullLike([])
270 ->defaultValue($defaults['route']['register']['context'])
271 ->scalarPrototype()->end()
272 ->end()
273 ->end()
274 ->end()
275 ->end()
276 ->end()
277 ->arrayNode('translate')
278 ->treatNullLike([])
279 ->defaultValue($defaults['translate'])
280 ->scalarPrototype()->end()
281 ->end()
282 ->arrayNode('contact')
283 ->addDefaultsIfNotSet()
284 ->children()
285 ->scalarNode('address')->cannotBeEmpty()->defaultValue($defaults['contact']['address'])->end()
286 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['contact']['name'])->end()
287 ->end()
288 ->end()
289 ->arrayNode('context')
290 ->treatNullLike([])
291 ->defaultValue($defaults['context'])
292 ->variablePrototype()->end()
293 ->end()
294 ->arrayNode('edit')
295 ->addDefaultsIfNotSet()
296 ->children()
297 ->arrayNode('admin')
298 ->treatNullLike([])
299 ->defaultValue($defaults['edit']['admin'])
300 ->variablePrototype()->end()
301 ->end()
302 ->arrayNode('field')
303 ->treatNullLike([])
304 ->defaultValue($defaults['edit']['field'])
305 ->variablePrototype()->end()
306 ->end()
307 ->arrayNode('route')
308 ->treatNullLike([])
309 ->defaultValue($defaults['edit']['route'])
310 ->scalarPrototype()->end()
311 ->end()
312 ->arrayNode('view')
313 ->addDefaultsIfNotSet()
314 ->children()
315 ->scalarNode('edit')->cannotBeEmpty()->defaultValue($defaults['edit']['view']['edit'])->end()
316 ->scalarNode('reset')->cannotBeEmpty()->defaultValue($defaults['edit']['view']['reset'])->end()
317 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['edit']['view']['name'])->end()
318 ->arrayNode('context')
319 ->treatNullLike([])
320 ->defaultValue($defaults['edit']['view']['context'])
321 ->variablePrototype()->end()
322 ->end()
323 ->end()
324 ->end()
325 ->end()
326 ->end()
327 ->arrayNode('index')
328 ->addDefaultsIfNotSet()
329 ->children()
330 ->arrayNode('route')
331 ->treatNullLike([])
332 ->defaultValue($defaults['index']['route'])
333 ->scalarPrototype()->end()
334 ->end()
335 ->arrayNode('view')
336 ->addDefaultsIfNotSet()
337 ->children()
338 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['index']['view']['name'])->end()
339 ->arrayNode('context')
340 ->treatNullLike([])
341 ->defaultValue($defaults['index']['view']['context'])
342 ->variablePrototype()->end()
343 ->end()
344 ->end()
345 ->end()
346 ->end()
347 ->end()
348 ->arrayNode('login')
349 ->addDefaultsIfNotSet()
350 ->children()
351 ->arrayNode('route')
352 ->treatNullLike([])
353 ->defaultValue($defaults['login']['route'])
354 ->scalarPrototype()->end()
355 ->end()
356 ->arrayNode('view')
357 ->addDefaultsIfNotSet()
358 ->children()
359 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['login']['view']['name'])->end()
360 ->scalarNode('form')->cannotBeEmpty()->defaultValue($defaults['login']['view']['form'])->end()
361 ->arrayNode('context')
362 ->treatNullLike([])
363 ->defaultValue($defaults['login']['view']['context'])
364 ->variablePrototype()->end()
365 ->end()
366 ->end()
367 ->end()
368 ->end()
369 ->end()
370 ->arrayNode('recover')
371 ->addDefaultsIfNotSet()
372 ->children()
373 ->arrayNode('route')
374 ->treatNullLike([])
375 ->defaultValue($defaults['recover']['route'])
376 ->scalarPrototype()->end()
377 ->end()
378 ->arrayNode('view')
379 ->addDefaultsIfNotSet()
380 ->children()
381 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['recover']['view']['name'])->end()
382 ->scalarNode('form')->cannotBeEmpty()->defaultValue($defaults['recover']['view']['form'])->end()
383 ->arrayNode('context')
384 ->treatNullLike([])
385 ->defaultValue($defaults['recover']['view']['context'])
386 ->variablePrototype()->end()
387 ->end()
388 ->end()
389 ->end()
390 ->arrayNode('mail')
391 ->addDefaultsIfNotSet()
392 ->children()
393 ->scalarNode('subject')->cannotBeEmpty()->defaultValue($defaults['recover']['mail']['subject'])->end()
394 ->scalarNode('html')->cannotBeEmpty()->defaultValue($defaults['recover']['mail']['html'])->end()
395 ->scalarNode('text')->cannotBeEmpty()->defaultValue($defaults['recover']['mail']['text'])->end()
396 ->arrayNode('context')
397 ->treatNullLike([])
398 ->defaultValue($defaults['recover']['mail']['context'])
399 ->variablePrototype()->end()
400 ->end()
401 ->end()
402 ->end()
403 ->end()
404 ->end()
405 ->arrayNode('register')
406 ->addDefaultsIfNotSet()
407 ->children()
408 ->arrayNode('admin')
409 ->treatNullLike([])
410 ->defaultValue($defaults['edit']['admin'])
411 ->variablePrototype()->end()
412 ->end()
413 ->arrayNode('field')
414 ->treatNullLike([])
415 ->defaultValue($defaults['register']['field'])
416 ->variablePrototype()->end()
417 ->end()
418 ->arrayNode('route')
419 ->treatNullLike([])
420 ->defaultValue($defaults['register']['route'])
421 ->scalarPrototype()->end()
422 ->end()
423 ->arrayNode('view')
424 ->addDefaultsIfNotSet()
425 ->children()
426 ->scalarNode('form')->cannotBeEmpty()->defaultValue($defaults['register']['view']['form'])->end()
427 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['register']['view']['name'])->end()
428 ->arrayNode('context')
429 ->treatNullLike([])
430 ->defaultValue($defaults['register']['view']['context'])
431 ->variablePrototype()->end()
432 ->end()
433 ->end()
434 ->end()
435 ->arrayNode('mail')
436 ->addDefaultsIfNotSet()
437 ->children()
438 ->scalarNode('subject')->cannotBeEmpty()->defaultValue($defaults['register']['mail']['subject'])->end()
439 ->scalarNode('html')->cannotBeEmpty()->defaultValue($defaults['register']['mail']['html'])->end()
440 ->scalarNode('text')->cannotBeEmpty()->defaultValue($defaults['register']['mail']['text'])->end()
441 ->arrayNode('context')
442 ->treatNullLike([])
443 ->defaultValue($defaults['register']['mail']['context'])
444 ->variablePrototype()->end()
445 ->end()
446 ->end()
447 ->end()
448 ->end()
449 ->end()
450 ->end()
451 ->end();
452
453 return $treeBuilder;
454 }
455 }