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 Ivory\CKEditorBundle\Exception\DependencyInjectionException; |
15
|
|
|
use Symfony\Component\Config\FileLocator; |
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
17
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
18
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\ConfigurableExtension; |
19
|
|
|
use Symfony\Component\HttpKernel\Kernel; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Ivory CKEditor extension. |
23
|
|
|
* |
24
|
|
|
* @author GeLo <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
class IvoryCKEditorExtension extends ConfigurableExtension |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* {@inheritdoc} |
30
|
|
|
*/ |
31
|
425 |
|
protected function loadInternal(array $config, ContainerBuilder $container) |
32
|
|
|
{ |
33
|
425 |
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
34
|
425 |
|
foreach (array('form', 'renderer', 'templating', 'twig') as $service) { |
35
|
425 |
|
$loader->load($service.'.xml'); |
36
|
400 |
|
} |
37
|
|
|
|
38
|
425 |
|
$this->registerConfig($config, $container); |
39
|
|
|
|
40
|
425 |
|
if (!isset($config['enable']) || $config['enable']) { |
41
|
408 |
|
$this->registerConfigs($config, $container); |
42
|
357 |
|
$this->registerPlugins($config, $container); |
43
|
357 |
|
$this->registerStylesSet($config, $container); |
44
|
357 |
|
$this->registerTemplates($config, $container); |
45
|
357 |
|
$this->registerToolbars($config, $container); |
46
|
336 |
|
$this->registerFilebrowsers($config, $container); |
47
|
|
|
} |
48
|
374 |
|
|
49
|
286 |
|
if (Kernel::VERSION_ID < 30000) { |
50
|
286 |
|
$container->getDefinition('ivory_ck_editor.form.type') |
51
|
286 |
|
->clearTag('form.type') |
52
|
264 |
|
->addTag('form.type', array('alias' => 'ckeditor')); |
53
|
374 |
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Registers the CKEditor config. |
58
|
|
|
* |
59
|
|
|
* @param array $config The CKEditor configuration |
60
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container The container. |
61
|
425 |
|
*/ |
62
|
|
|
private function registerConfig(array $config, ContainerBuilder $container) |
63
|
425 |
|
{ |
64
|
|
|
$formType = $container->getDefinition('ivory_ck_editor.form.type'); |
65
|
425 |
|
|
66
|
17 |
|
if (isset($config['enable'])) { |
67
|
16 |
|
$formType->addMethodCall('isEnable', array($config['enable'])); |
68
|
|
|
} |
69
|
425 |
|
|
70
|
17 |
|
if (isset($config['async'])) { |
71
|
16 |
|
$formType->addMethodCall('isAsync', array($config['async'])); |
72
|
|
|
} |
73
|
425 |
|
|
74
|
17 |
|
if (isset($config['auto_inline'])) { |
75
|
16 |
|
$formType->addMethodCall('isAutoInline', array($config['auto_inline'])); |
76
|
|
|
} |
77
|
425 |
|
|
78
|
17 |
|
if (isset($config['inline'])) { |
79
|
16 |
|
$formType->addMethodCall('isInline', array($config['inline'])); |
80
|
|
|
} |
81
|
425 |
|
|
82
|
17 |
|
if (isset($config['autoload'])) { |
83
|
16 |
|
$formType->addMethodCall('isAutoload', array($config['autoload'])); |
84
|
|
|
} |
85
|
425 |
|
|
86
|
17 |
|
if (isset($config['jquery'])) { |
87
|
16 |
|
$formType->addMethodCall('useJquery', array($config['jquery'])); |
88
|
|
|
} |
89
|
425 |
|
|
90
|
17 |
|
if (isset($config['require_js'])) { |
91
|
16 |
|
$formType->addMethodCall('useRequireJs', array($config['require_js'])); |
92
|
|
|
} |
93
|
425 |
|
|
94
|
17 |
|
if (isset($config['input_sync'])) { |
95
|
16 |
|
$formType->addMethodCall('isInputSync', array($config['input_sync'])); |
96
|
|
|
} |
97
|
425 |
|
|
98
|
17 |
|
if (isset($config['base_path'])) { |
99
|
16 |
|
$formType->addMethodCall('setBasePath', array($config['base_path'])); |
100
|
|
|
} |
101
|
425 |
|
|
102
|
17 |
|
if (isset($config['js_path'])) { |
103
|
16 |
|
$formType->addMethodCall('setJsPath', array($config['js_path'])); |
104
|
|
|
} |
105
|
425 |
|
|
106
|
17 |
|
if (isset($config['jquery_path'])) { |
107
|
16 |
|
$formType->addMethodCall('setJqueryPath', array($config['jquery_path'])); |
108
|
425 |
|
} |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Registers the CKEditor configs. |
113
|
|
|
* |
114
|
|
|
* @param array $config The CKEditor configuration. |
115
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container The container. |
116
|
|
|
* |
117
|
|
|
* @throws \Ivory\CKEditorBundle\Exception\DependencyInjectionException If the default config does not exist. |
118
|
408 |
|
*/ |
119
|
|
|
private function registerConfigs(array $config, ContainerBuilder $container) |
120
|
408 |
|
{ |
121
|
272 |
|
if (empty($config['configs'])) { |
122
|
|
|
return; |
123
|
|
|
} |
124
|
136 |
|
|
125
|
|
|
$definition = $container->getDefinition('ivory_ck_editor.config_manager'); |
126
|
102 |
|
$definition->addMethodCall('setConfigs', array($config['configs'])); |
127
|
102 |
|
|
128
|
102 |
|
if (!isset($config['default_config']) && !empty($config['configs'])) { |
129
|
96 |
|
reset($config['configs']); |
130
|
|
|
$config['default_config'] = key($config['configs']); |
131
|
102 |
|
} |
132
|
51 |
|
|
133
|
17 |
|
if (isset($config['default_config'])) { |
134
|
|
|
if (!isset($config['configs'][$config['default_config']])) { |
135
|
|
|
throw DependencyInjectionException::invalidDefaultConfig($config['default_config']); |
136
|
34 |
|
} |
137
|
32 |
|
|
138
|
85 |
|
$definition->addMethodCall('setDefaultConfig', array($config['default_config'])); |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Registers the CKEditor plugins. |
144
|
|
|
* |
145
|
|
|
* @param array $config The CKEditor configuration. |
146
|
357 |
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container The container. |
147
|
|
|
*/ |
148
|
357 |
|
private function registerPlugins(array $config, ContainerBuilder $container) |
149
|
340 |
|
{ |
150
|
|
|
if (!empty($config['plugins'])) { |
151
|
|
|
$container |
152
|
17 |
|
->getDefinition('ivory_ck_editor.plugin_manager') |
153
|
|
|
->addMethodCall('setPlugins', array($config['plugins'])); |
154
|
17 |
|
} |
155
|
17 |
|
} |
156
|
16 |
|
|
157
|
17 |
|
/** |
158
|
|
|
* Registers the CKEditor styles set. |
159
|
|
|
* |
160
|
|
|
* @param array $config The CKEditor configuration. |
161
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container The container. |
162
|
|
|
*/ |
163
|
|
|
private function registerStylesSet(array $config, ContainerBuilder $container) |
164
|
|
|
{ |
165
|
357 |
|
if (empty($config['styles'])) { |
166
|
|
|
return; |
167
|
357 |
|
} |
168
|
340 |
|
|
169
|
|
|
$stylesSets = $config['styles']; |
170
|
|
|
|
171
|
17 |
|
foreach ($stylesSets as &$stylesSet) { |
172
|
|
|
foreach ($stylesSet as &$value) { |
173
|
17 |
|
$value = array_filter($value); |
174
|
17 |
|
} |
175
|
16 |
|
} |
176
|
17 |
|
|
177
|
|
|
$container |
178
|
|
|
->getDefinition('ivory_ck_editor.styles_set_manager') |
179
|
|
|
->addMethodCall('setStylesSets', array($stylesSets)); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* Registers the CKEditor templates. |
184
|
357 |
|
* |
185
|
|
|
* @param array $config The CKEditor configuration. |
186
|
357 |
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container The container. |
187
|
340 |
|
*/ |
188
|
|
|
private function registerTemplates(array $config, ContainerBuilder $container) |
189
|
|
|
{ |
190
|
17 |
|
if (!empty($config['templates'])) { |
191
|
|
|
$container |
192
|
17 |
|
->getDefinition('ivory_ck_editor.template_manager') |
193
|
17 |
|
->addMethodCall('setTemplates', array($config['templates'])); |
194
|
16 |
|
} |
195
|
17 |
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* Registers the CKEditor toolbars. |
199
|
|
|
* |
200
|
|
|
* @param array $config The CKEditor configuration. |
201
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container The container. |
202
|
|
|
*/ |
203
|
357 |
|
private function registerToolbars(array $config, ContainerBuilder $container) |
204
|
|
|
{ |
205
|
357 |
|
$definition = $container->getDefinition('ivory_ck_editor.toolbar_manager'); |
206
|
340 |
|
|
207
|
|
|
if (!empty($config['toolbars']['items'])) { |
208
|
|
|
$definition->addMethodCall('setItems', array($config['toolbars']['items'])); |
209
|
|
|
} |
210
|
17 |
|
|
211
|
17 |
|
if (!empty($config['toolbars']['configs'])) { |
212
|
17 |
|
$definition->addMethodCall('setToolbars', array($config['toolbars']['configs'])); |
213
|
|
|
} |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* Registers the CKEditor filebrowsers. |
218
|
|
|
* |
219
|
|
|
* @param array $config The CKEditor configuration. |
220
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container The container. |
221
|
|
|
*/ |
222
|
|
|
private function registerFilebrowsers(array $config, ContainerBuilder $container) |
223
|
136 |
|
{ |
224
|
|
|
if (!empty($config['filebrowsers'])) { |
225
|
136 |
|
$container |
226
|
119 |
|
->getDefinition('ivory_ck_editor.form.type') |
227
|
|
|
->addMethodCall('setFilebrowsers', array($config['filebrowsers'])); |
228
|
119 |
|
} |
229
|
119 |
|
} |
230
|
|
|
} |
231
|
|
|
|