-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathConfiguration.php
More file actions
128 lines (119 loc) · 4.59 KB
/
Configuration.php
File metadata and controls
128 lines (119 loc) · 4.59 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
<?php
/*
* This file is part of the ElaoFormTranslation bundle.
*
* Copyright (C) Elao
*
* @author Elao <contact@elao.com>
*/
namespace Elao\Bundle\FormTranslationBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
/**
* ElaoFormTranslation bundle configuration
*
* @author Thomas Jarrand <thomas.jarrand@gmail.com>
*/
class Configuration implements ConfigurationInterface
{
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('elao_form_translation');
$rootNode = method_exists($treeBuilder, 'getRootNode') ? $treeBuilder->getRootNode() : $treeBuilder->root('elao_form_translation');
$rootNode
->info('<info>Activate the Form Tree component (used to generate label translation keys)</info>')
->canBeDisabled()
->children()
->booleanNode('auto_generate')
->info('<info>Generate translation keys for all missing keys</info>')
->defaultFalse()
->end()
->arrayNode('keys')
->info('<info>Customize available keys</info>')
->addDefaultsIfNotSet()
->children()
->append(
$this->addKeysConfig(
'form',
[
'[label]' => 'label',
'[help]' => 'help',
'[attr][placeholder]' => 'placeholder',
]
)
)
->append(
$this->addKeysConfig(
'collection',
[
'[label_add]' => 'label_add',
'[label_delete]' => 'label_delete',
]
)
)
->append(
$this->addKeysConfig(
'choice',
[
'[placeholder]' => 'placeholder',
'[empty_value]' => 'empty_value',
]
)
)
->end()
->end()
->arrayNode('blocks')
->info('<info>Customize the ways keys are built</info>')
->addDefaultsIfNotSet()
->children()
->scalarNode('children')
->defaultValue('children')
->info('Prefix for children nodes (string|false)')
->end()
->scalarNode('prototype')
->defaultValue('prototype')
->info('Prefix for prototype nodes (string|false)')
->end()
->scalarNode('root')
->defaultValue('form')
->info('Prefix at the root of the key (string|false)')
->end()
->scalarNode('separator')
->defaultValue('.')
->info('Separator te be used between nodes (string|false)')
->end()
->end()
->end()
->scalarNode('default_translation_domain')
->info('<info>Default translation domain for all forms</info>')
->defaultNull()
->end()
->end();
return $treeBuilder;
}
/**
* Add Keys Config
*
* @param string $key
* @param array $default
*
* @return ArrayNodeDefinition|NodeDefinition
*/
public function addKeysConfig($key, $default = [])
{
$treeBuilder = new TreeBuilder($key);
$node = method_exists($treeBuilder, 'getRootNode') ? $treeBuilder->getRootNode() : $treeBuilder->root($key);
$node
->prototype('scalar')
->isRequired()
->end()
->normalizeKeys(false)
->defaultValue($default);
return $node;
}
}