|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Sonata Project package. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Thomas Rabaix <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Sonata\TranslationBundle\DependencyInjection; |
|
15
|
|
|
|
|
16
|
|
|
use Sonata\TranslationBundle\Enum\TranslationFilterMode; |
|
17
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
|
18
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @author Nicolas Bastien <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
|
class Configuration implements ConfigurationInterface |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* {@inheritdoc} |
|
27
|
|
|
*/ |
|
28
|
|
|
public function getConfigTreeBuilder() |
|
29
|
|
|
{ |
|
30
|
|
|
$treeBuilder = new TreeBuilder('sonata_translation'); |
|
31
|
|
|
|
|
32
|
|
|
$rootNode = $treeBuilder->getRootNode(); |
|
33
|
|
|
|
|
34
|
|
|
$rootNode |
|
35
|
|
|
->children() |
|
36
|
|
|
->arrayNode('locales') |
|
37
|
|
|
->info('The list of your frontend locales in which your models will be translatable.') |
|
38
|
|
|
->requiresAtLeastOneElement() |
|
39
|
|
|
->prototype('scalar')->end() |
|
40
|
|
|
->end() |
|
41
|
|
|
->scalarNode('default_locale') |
|
42
|
|
|
->defaultValue('en') |
|
43
|
|
|
->info('The frontend locale that is used by default.') |
|
44
|
|
|
->end() |
|
45
|
|
|
->enumNode('default_filter_mode') |
|
46
|
|
|
->values(TranslationFilterMode::AVAILABLE_FILTER_TYPES) |
|
47
|
|
|
->defaultValue(TranslationFilterMode::GEDMO) |
|
48
|
|
|
->info('The filter mode that is used by default.') |
|
49
|
|
|
->end() |
|
50
|
|
|
->arrayNode('gedmo') |
|
51
|
|
|
->canBeEnabled() |
|
52
|
|
|
->children() |
|
53
|
|
|
->arrayNode('implements') |
|
54
|
|
|
->requiresAtLeastOneElement() |
|
55
|
|
|
->prototype('scalar')->end() |
|
56
|
|
|
->end() |
|
57
|
|
|
->arrayNode('instanceof') |
|
58
|
|
|
->requiresAtLeastOneElement() |
|
59
|
|
|
->prototype('scalar')->end() |
|
60
|
|
|
->end() |
|
61
|
|
|
->end() |
|
62
|
|
|
->end() |
|
63
|
|
|
->arrayNode('knplabs') |
|
64
|
|
|
->canBeEnabled() |
|
65
|
|
|
->children() |
|
66
|
|
|
->arrayNode('implements') |
|
67
|
|
|
->requiresAtLeastOneElement() |
|
68
|
|
|
->prototype('scalar')->end() |
|
69
|
|
|
->end() |
|
70
|
|
|
->arrayNode('instanceof') |
|
71
|
|
|
->requiresAtLeastOneElement() |
|
72
|
|
|
->prototype('scalar')->end() |
|
73
|
|
|
->end() |
|
74
|
|
|
->end() |
|
75
|
|
|
->end() |
|
76
|
|
|
->arrayNode('phpcr') |
|
77
|
|
|
->canBeEnabled() |
|
78
|
|
|
->children() |
|
79
|
|
|
->arrayNode('implements') |
|
80
|
|
|
->requiresAtLeastOneElement() |
|
81
|
|
|
->prototype('scalar')->end() |
|
82
|
|
|
->end() |
|
83
|
|
|
->arrayNode('instanceof') |
|
84
|
|
|
->requiresAtLeastOneElement() |
|
85
|
|
|
->prototype('scalar')->end() |
|
86
|
|
|
->end() |
|
87
|
|
|
->end() |
|
88
|
|
|
->end() |
|
89
|
|
|
->booleanNode('locale_switcher') |
|
90
|
|
|
->info('Enable the global locale switcher services.') |
|
91
|
|
|
->defaultFalse() |
|
92
|
|
|
->end() |
|
93
|
|
|
// NEXT_MAJOR: Fix locale to country flag mapping OR remove country flags entirely |
|
94
|
|
|
->booleanNode('locale_switcher_show_country_flags') |
|
95
|
|
|
->info('Whether the language switcher should show languages as flags') |
|
96
|
|
|
->defaultTrue() |
|
97
|
|
|
->end() |
|
98
|
|
|
->end() |
|
99
|
|
|
->beforeNormalization() |
|
100
|
|
|
->ifTrue(static function ($v) {return !isset($v['locale_switcher_show_country_flags']) || true === $v['locale_switcher_show_country_flags']; }) |
|
101
|
|
|
->then(static function ($v) { |
|
102
|
|
|
@trigger_error(sprintf( |
|
|
|
|
|
|
103
|
|
|
'Showing the country flags is deprecated. The flags will be removed in the next major version. Please set "%s" to false to avoid this message.', |
|
104
|
|
|
'sonata_translation.locale_switcher_show_country_flags' |
|
105
|
|
|
), E_USER_DEPRECATED); |
|
106
|
|
|
$v['locale_switcher_show_country_flags'] = $v['locale_switcher_show_country_flags'] ?? true; |
|
107
|
|
|
|
|
108
|
|
|
return $v; |
|
109
|
|
|
}) |
|
110
|
|
|
->end(); |
|
111
|
|
|
|
|
112
|
|
|
return $treeBuilder; |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: