|
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
|
|
|
protected function loadInternal(array $config, ContainerBuilder $container) |
|
32
|
|
|
{ |
|
33
|
|
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
34
|
|
|
foreach (array('form', 'renderer', 'templating', 'twig') as $service) { |
|
35
|
|
|
$loader->load($service.'.xml'); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
$this->registerConfig($config, $container); |
|
39
|
|
|
|
|
40
|
|
|
if (!isset($config['enable']) || $config['enable']) { |
|
41
|
|
|
$this->registerConfigs($config, $container); |
|
42
|
|
|
$this->registerPlugins($config, $container); |
|
43
|
|
|
$this->registerStylesSet($config, $container); |
|
44
|
|
|
$this->registerTemplates($config, $container); |
|
45
|
|
|
$this->registerToolbars($config, $container); |
|
46
|
|
|
$this->registerFilebrowsers($config, $container); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
if (Kernel::VERSION_ID < 30000) { |
|
50
|
|
|
$container->getDefinition('ivory_ck_editor.form.type') |
|
51
|
|
|
->clearTag('form.type') |
|
52
|
|
|
->addTag('form.type', array('alias' => 'ckeditor')); |
|
53
|
|
|
} |
|
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
|
|
|
*/ |
|
62
|
|
|
private function registerConfig(array $config, ContainerBuilder $container) |
|
63
|
|
|
{ |
|
64
|
|
|
$formType = $container->getDefinition('ivory_ck_editor.form.type'); |
|
65
|
|
|
|
|
66
|
|
|
if (isset($config['enable'])) { |
|
67
|
|
|
$formType->addMethodCall('isEnable', array($config['enable'])); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
if (isset($config['async'])) { |
|
71
|
|
|
$formType->addMethodCall('isAsync', array($config['async'])); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
if (isset($config['auto_inline'])) { |
|
75
|
|
|
$formType->addMethodCall('isAutoInline', array($config['auto_inline'])); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
if (isset($config['inline'])) { |
|
79
|
|
|
$formType->addMethodCall('isInline', array($config['inline'])); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
if (isset($config['autoload'])) { |
|
83
|
|
|
$formType->addMethodCall('isAutoload', array($config['autoload'])); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
if (isset($config['jquery'])) { |
|
87
|
|
|
$formType->addMethodCall('useJquery', array($config['jquery'])); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
if (isset($config['require_js'])) { |
|
91
|
|
|
$formType->addMethodCall('useRequireJs', array($config['require_js'])); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
if (isset($config['input_sync'])) { |
|
95
|
|
|
$formType->addMethodCall('isInputSync', array($config['input_sync'])); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
if (isset($config['base_path'])) { |
|
99
|
|
|
$formType->addMethodCall('setBasePath', array($config['base_path'])); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
if (isset($config['js_path'])) { |
|
103
|
|
|
$formType->addMethodCall('setJsPath', array($config['js_path'])); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
if (isset($config['jquery_path'])) { |
|
107
|
|
|
$formType->addMethodCall('setJqueryPath', array($config['jquery_path'])); |
|
108
|
|
|
} |
|
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
|
|
|
*/ |
|
119
|
|
|
private function registerConfigs(array $config, ContainerBuilder $container) |
|
120
|
|
|
{ |
|
121
|
|
|
if (empty($config['configs'])) { |
|
122
|
|
|
return; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
$definition = $container->getDefinition('ivory_ck_editor.config_manager'); |
|
126
|
|
|
$definition->addMethodCall('setConfigs', array($config['configs'])); |
|
127
|
|
|
|
|
128
|
|
|
if (!isset($config['default_config']) && !empty($config['configs'])) { |
|
129
|
|
|
reset($config['configs']); |
|
130
|
|
|
$config['default_config'] = key($config['configs']); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
if (isset($config['default_config'])) { |
|
134
|
|
|
if (!isset($config['configs'][$config['default_config']])) { |
|
135
|
|
|
throw DependencyInjectionException::invalidDefaultConfig($config['default_config']); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
$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
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container The container. |
|
147
|
|
|
*/ |
|
148
|
|
|
private function registerPlugins(array $config, ContainerBuilder $container) |
|
149
|
|
|
{ |
|
150
|
|
|
if (!empty($config['plugins'])) { |
|
151
|
|
|
$container |
|
152
|
|
|
->getDefinition('ivory_ck_editor.plugin_manager') |
|
153
|
|
|
->addMethodCall('setPlugins', array($config['plugins'])); |
|
154
|
|
|
} |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
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
|
|
|
if (empty($config['styles'])) { |
|
166
|
|
|
return; |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
$stylesSets = $config['styles']; |
|
170
|
|
|
|
|
171
|
|
|
foreach ($stylesSets as &$stylesSet) { |
|
172
|
|
|
foreach ($stylesSet as &$value) { |
|
173
|
|
|
$value = array_filter($value); |
|
174
|
|
|
} |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
$container |
|
178
|
|
|
->getDefinition('ivory_ck_editor.styles_set_manager') |
|
179
|
|
|
->addMethodCall('setStylesSets', array($stylesSets)); |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
/** |
|
183
|
|
|
* Registers the CKEditor templates. |
|
184
|
|
|
* |
|
185
|
|
|
* @param array $config The CKEditor configuration. |
|
186
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container The container. |
|
187
|
|
|
*/ |
|
188
|
|
|
private function registerTemplates(array $config, ContainerBuilder $container) |
|
189
|
|
|
{ |
|
190
|
|
|
if (!empty($config['templates'])) { |
|
191
|
|
|
$container |
|
192
|
|
|
->getDefinition('ivory_ck_editor.template_manager') |
|
193
|
|
|
->addMethodCall('setTemplates', array($config['templates'])); |
|
194
|
|
|
} |
|
195
|
|
|
} |
|
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
|
|
|
private function registerToolbars(array $config, ContainerBuilder $container) |
|
204
|
|
|
{ |
|
205
|
|
|
$definition = $container->getDefinition('ivory_ck_editor.toolbar_manager'); |
|
206
|
|
|
|
|
207
|
|
|
if (!empty($config['toolbars']['items'])) { |
|
208
|
|
|
$definition->addMethodCall('setItems', array($config['toolbars']['items'])); |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
if (!empty($config['toolbars']['configs'])) { |
|
212
|
|
|
$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
|
|
|
{ |
|
224
|
|
|
if (!empty($config['filebrowsers'])) { |
|
225
|
|
|
$container |
|
226
|
|
|
->getDefinition('ivory_ck_editor.form.type') |
|
227
|
|
|
->addMethodCall('setFilebrowsers', array($config['filebrowsers'])); |
|
228
|
|
|
} |
|
229
|
|
|
} |
|
230
|
|
|
} |
|
231
|
|
|
|