1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Ivory CKEditor package. |
5
|
|
|
* |
6
|
|
|
* (c) Eric GELOEN <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please read the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Ivory\CKEditorBundle\DependencyInjection; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
15
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Ivory CKEditor configuration. |
19
|
|
|
* |
20
|
|
|
* @author GeLo <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class Configuration implements ConfigurationInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* {@inheritdoc} |
26
|
|
|
*/ |
27
|
|
|
public function getConfigTreeBuilder() |
28
|
|
|
{ |
29
|
|
|
$treeBuilder = $this->createTreeBuilder(); |
30
|
|
|
$treeBuilder |
31
|
|
|
->root('ivory_ck_editor') |
32
|
|
|
->children() |
33
|
|
|
->booleanNode('enable')->end() |
34
|
|
|
->booleanNode('async')->end() |
35
|
|
|
->booleanNode('auto_inline')->end() |
36
|
|
|
->booleanNode('inline')->end() |
37
|
|
|
->booleanNode('autoload')->end() |
38
|
|
|
->booleanNode('jquery')->end() |
39
|
|
|
->booleanNode('require_js')->end() |
40
|
|
|
->booleanNode('input_sync')->end() |
41
|
|
|
->scalarNode('base_path')->end() |
42
|
|
|
->scalarNode('js_path')->end() |
43
|
|
|
->scalarNode('jquery_path')->end() |
44
|
|
|
->scalarNode('default_config')->end() |
45
|
|
|
->append($this->createConfigsNode()) |
46
|
|
|
->append($this->createPluginsNode()) |
47
|
|
|
->append($this->createStylesNode()) |
48
|
|
|
->append($this->createTemplatesNode()) |
49
|
|
|
->append($this->createFilebrowsersNode()) |
50
|
|
|
->append($this->createToolbarsNode()) |
51
|
|
|
->end(); |
52
|
|
|
|
53
|
|
|
return $treeBuilder; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Creates the configs node. |
58
|
|
|
* |
59
|
|
|
* @return \Symfony\Component\Config\Definition\Builder\NodeDefinition The configs node. |
60
|
|
|
*/ |
61
|
|
|
private function createConfigsNode() |
62
|
|
|
{ |
63
|
|
|
return $this->createNode('configs') |
64
|
|
|
->normalizeKeys(false) |
65
|
|
|
->useAttributeAsKey('name') |
66
|
|
|
->prototype('array') |
67
|
|
|
->normalizeKeys(false) |
68
|
|
|
->useAttributeAsKey('name') |
69
|
|
|
->prototype('variable')->end() |
70
|
|
|
->end(); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Creates the plugins node. |
75
|
|
|
* |
76
|
|
|
* @return \Symfony\Component\Config\Definition\Builder\NodeDefinition The plugins node. |
77
|
|
|
*/ |
78
|
|
|
private function createPluginsNode() |
79
|
|
|
{ |
80
|
|
|
return $this->createNode('plugins') |
81
|
|
|
->normalizeKeys(false) |
82
|
|
|
->useAttributeAsKey('name') |
83
|
|
|
->prototype('array') |
84
|
|
|
->children() |
85
|
|
|
->scalarNode('path')->end() |
86
|
|
|
->scalarNode('filename')->end() |
87
|
|
|
->end() |
88
|
|
|
->end(); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Creates the styles node. |
93
|
|
|
* |
94
|
|
|
* @return \Symfony\Component\Config\Definition\Builder\NodeDefinition The styles node. |
95
|
|
|
*/ |
96
|
|
View Code Duplication |
private function createStylesNode() |
|
|
|
|
97
|
|
|
{ |
98
|
|
|
return $this->createNode('styles') |
99
|
|
|
->normalizeKeys(false) |
100
|
|
|
->useAttributeAsKey('name') |
101
|
|
|
->prototype('array') |
102
|
|
|
->prototype('array') |
103
|
|
|
->children() |
104
|
|
|
->scalarNode('name')->end() |
105
|
|
|
->scalarNode('type')->end() |
106
|
|
|
->scalarNode('widget')->end() |
107
|
|
|
->variableNode('element')->end() |
108
|
|
|
->arrayNode('styles') |
109
|
|
|
->normalizeKeys(false) |
110
|
|
|
->useAttributeAsKey('name') |
111
|
|
|
->prototype('scalar')->end() |
112
|
|
|
->end() |
113
|
|
|
->arrayNode('attributes') |
114
|
|
|
->normalizeKeys(false) |
115
|
|
|
->useAttributeAsKey('name') |
116
|
|
|
->prototype('scalar')->end() |
117
|
|
|
->end() |
118
|
|
|
->end() |
119
|
|
|
->end() |
120
|
|
|
->end(); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Creates the templates node. |
125
|
|
|
* |
126
|
|
|
* @return \Symfony\Component\Config\Definition\Builder\NodeDefinition The templates node. |
127
|
|
|
*/ |
128
|
|
View Code Duplication |
private function createTemplatesNode() |
|
|
|
|
129
|
|
|
{ |
130
|
|
|
return $this->createNode('templates') |
131
|
|
|
->normalizeKeys(false) |
132
|
|
|
->useAttributeAsKey('name') |
133
|
|
|
->prototype('array') |
134
|
|
|
->children() |
135
|
|
|
->scalarNode('imagesPath')->end() |
136
|
|
|
->arrayNode('templates') |
137
|
|
|
->prototype('array') |
138
|
|
|
->children() |
139
|
|
|
->scalarNode('title')->end() |
140
|
|
|
->scalarNode('image')->end() |
141
|
|
|
->scalarNode('description')->end() |
142
|
|
|
->scalarNode('html')->end() |
143
|
|
|
->scalarNode('template')->end() |
144
|
|
|
->arrayNode('template_parameters') |
145
|
|
|
->normalizeKeys(false) |
146
|
|
|
->useAttributeAsKey('name') |
147
|
|
|
->prototype('scalar')->end() |
148
|
|
|
->end() |
149
|
|
|
->end() |
150
|
|
|
->end() |
151
|
|
|
->end() |
152
|
|
|
->end() |
153
|
|
|
->end(); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Creates the filebrowsers node. |
158
|
|
|
* |
159
|
|
|
* @return \Symfony\Component\Config\Definition\Builder\NodeDefinition The filebrowsers node. |
160
|
|
|
*/ |
161
|
|
|
private function createFilebrowsersNode() |
162
|
|
|
{ |
163
|
|
|
return $this->createNode('filebrowsers') |
164
|
|
|
->useAttributeAsKey('name') |
165
|
|
|
->prototype('scalar') |
166
|
|
|
->end(); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* Creates the toolbars node. |
171
|
|
|
* |
172
|
|
|
* @return \Symfony\Component\Config\Definition\Builder\NodeDefinition The toolbars node. |
173
|
|
|
*/ |
174
|
|
|
private function createToolbarsNode() |
175
|
|
|
{ |
176
|
|
|
return $this->createNode('toolbars') |
177
|
|
|
->addDefaultsIfNotSet() |
178
|
|
|
->children() |
179
|
|
|
->arrayNode('configs') |
180
|
|
|
->useAttributeAsKey('name') |
181
|
|
|
->prototype('array') |
182
|
|
|
->prototype('variable')->end() |
183
|
|
|
->end() |
184
|
|
|
->end() |
185
|
|
|
->arrayNode('items') |
186
|
|
|
->useAttributeAsKey('name') |
187
|
|
|
->prototype('array') |
188
|
|
|
->prototype('variable')->end() |
189
|
|
|
->end() |
190
|
|
|
->end() |
191
|
|
|
->end(); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Creates a node. |
196
|
|
|
* |
197
|
|
|
* @param string $name The node name. |
198
|
|
|
* |
199
|
|
|
* @return \Symfony\Component\Config\Definition\Builder\NodeDefinition The node. |
200
|
|
|
*/ |
201
|
|
|
private function createNode($name) |
202
|
|
|
{ |
203
|
|
|
return $this->createTreeBuilder()->root($name); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* Creates a tree builder. |
208
|
|
|
* |
209
|
|
|
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder. |
210
|
|
|
*/ |
211
|
|
|
private function createTreeBuilder() |
212
|
|
|
{ |
213
|
|
|
return new TreeBuilder(); |
214
|
|
|
} |
215
|
|
|
} |
216
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.