|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the FOSCKEditor Bundle. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) 2018 - present Friends of Symfony |
|
7
|
|
|
* (c) 2009 - 2017 Eric GELOEN <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* For the full copyright and license information, please read the LICENSE |
|
10
|
|
|
* file that was distributed with this source code. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace FOS\CKEditorBundle\DependencyInjection; |
|
14
|
|
|
|
|
15
|
|
|
use FOS\CKEditorBundle\Exception\DependencyInjectionException; |
|
16
|
|
|
use Symfony\Component\Config\FileLocator; |
|
17
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
18
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
|
19
|
|
|
use Symfony\Component\Form\AbstractType; |
|
20
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\ConfigurableExtension; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @author GeLo <[email protected]> |
|
24
|
|
|
*/ |
|
25
|
|
|
class FOSCKEditorExtension extends ConfigurableExtension |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* {@inheritdoc} |
|
29
|
|
|
*/ |
|
30
|
|
|
protected function loadInternal(array $config, ContainerBuilder $container) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->loadResources($container); |
|
33
|
|
|
$this->registerConfig($config, $container); |
|
34
|
|
|
|
|
35
|
|
|
if (!isset($config['enable']) || $config['enable']) { |
|
36
|
|
|
$this->registerConfigs($config, $container); |
|
37
|
|
|
$this->registerPlugins($config, $container); |
|
38
|
|
|
$this->registerStylesSet($config, $container); |
|
39
|
|
|
$this->registerTemplates($config, $container); |
|
40
|
|
|
$this->registerToolbars($config, $container); |
|
41
|
|
|
$this->registerFilebrowsers($config, $container); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
if (!method_exists(AbstractType::class, 'getBlockPrefix')) { |
|
45
|
|
|
$container->getDefinition('fos_ck_editor.form.type') |
|
46
|
|
|
->clearTag('form.type') |
|
47
|
|
|
->addTag('form.type', ['alias' => 'ckeditor']); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$bundles = $container->getParameter('kernel.bundles'); |
|
51
|
|
|
|
|
52
|
|
|
if (isset($bundles['IvoryCKEditorBundle'])) { |
|
53
|
|
|
@trigger_error( |
|
54
|
|
|
"IvoryCKEditorBundle isn't maintained anymore and should be replaced with FOSCKEditorBundle.", |
|
55
|
|
|
E_USER_DEPRECATED |
|
56
|
|
|
); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @param ContainerBuilder $container |
|
62
|
|
|
*/ |
|
63
|
|
|
private function loadResources(ContainerBuilder $container) |
|
64
|
|
|
{ |
|
65
|
|
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
66
|
|
|
|
|
67
|
|
|
$resources = [ |
|
68
|
|
|
'builder', |
|
69
|
|
|
'command', |
|
70
|
|
|
'form', |
|
71
|
|
|
'installer', |
|
72
|
|
|
'renderer', |
|
73
|
|
|
'templating', |
|
74
|
|
|
'twig', |
|
75
|
|
|
]; |
|
76
|
|
|
|
|
77
|
|
|
foreach ($resources as $resource) { |
|
78
|
|
|
$loader->load($resource.'.xml'); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @param array $config |
|
84
|
|
|
* @param ContainerBuilder $container |
|
85
|
|
|
*/ |
|
86
|
|
|
private function registerConfig(array $config, ContainerBuilder $container) |
|
87
|
|
|
{ |
|
88
|
|
|
$formType = $container->getDefinition('fos_ck_editor.form.type'); |
|
89
|
|
|
|
|
90
|
|
|
if (isset($config['enable'])) { |
|
91
|
|
|
$formType->addMethodCall('isEnable', [$config['enable']]); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
if (isset($config['async'])) { |
|
95
|
|
|
$formType->addMethodCall('isAsync', [$config['async']]); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
if (isset($config['auto_inline'])) { |
|
99
|
|
|
$formType->addMethodCall('isAutoInline', [$config['auto_inline']]); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
if (isset($config['inline'])) { |
|
103
|
|
|
$formType->addMethodCall('isInline', [$config['inline']]); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
if (isset($config['autoload'])) { |
|
107
|
|
|
$formType->addMethodCall('isAutoload', [$config['autoload']]); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
if (isset($config['jquery'])) { |
|
111
|
|
|
$formType->addMethodCall('useJquery', [$config['jquery']]); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
if (isset($config['require_js'])) { |
|
115
|
|
|
$formType->addMethodCall('useRequireJs', [$config['require_js']]); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
if (isset($config['input_sync'])) { |
|
119
|
|
|
$formType->addMethodCall('isInputSync', [$config['input_sync']]); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
if (isset($config['base_path'])) { |
|
123
|
|
|
$formType->addMethodCall('setBasePath', [$config['base_path']]); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
if (isset($config['js_path'])) { |
|
127
|
|
|
$formType->addMethodCall('setJsPath', [$config['js_path']]); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
if (isset($config['jquery_path'])) { |
|
131
|
|
|
$formType->addMethodCall('setJqueryPath', [$config['jquery_path']]); |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* @param array $config |
|
137
|
|
|
* @param ContainerBuilder $container |
|
138
|
|
|
* |
|
139
|
|
|
* @throws DependencyInjectionException |
|
140
|
|
|
*/ |
|
141
|
|
|
private function registerConfigs(array $config, ContainerBuilder $container) |
|
142
|
|
|
{ |
|
143
|
|
|
if (empty($config['configs'])) { |
|
144
|
|
|
return; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
$definition = $container->getDefinition('fos_ck_editor.config_manager'); |
|
148
|
|
|
$definition->addMethodCall('setConfigs', [$config['configs']]); |
|
149
|
|
|
|
|
150
|
|
|
if (!isset($config['default_config']) && !empty($config['configs'])) { |
|
151
|
|
|
reset($config['configs']); |
|
152
|
|
|
$config['default_config'] = key($config['configs']); |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
if (isset($config['default_config'])) { |
|
156
|
|
|
if (!isset($config['configs'][$config['default_config']])) { |
|
157
|
|
|
throw DependencyInjectionException::invalidDefaultConfig($config['default_config']); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
$definition->addMethodCall('setDefaultConfig', [$config['default_config']]); |
|
161
|
|
|
} |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* @param array $config |
|
166
|
|
|
* @param ContainerBuilder $container |
|
167
|
|
|
*/ |
|
168
|
|
|
private function registerPlugins(array $config, ContainerBuilder $container) |
|
169
|
|
|
{ |
|
170
|
|
|
if (!empty($config['plugins'])) { |
|
171
|
|
|
$container |
|
172
|
|
|
->getDefinition('fos_ck_editor.plugin_manager') |
|
173
|
|
|
->addMethodCall('setPlugins', [$config['plugins']]); |
|
174
|
|
|
} |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* @param array $config |
|
179
|
|
|
* @param ContainerBuilder $container |
|
180
|
|
|
*/ |
|
181
|
|
|
private function registerStylesSet(array $config, ContainerBuilder $container) |
|
182
|
|
|
{ |
|
183
|
|
|
if (empty($config['styles'])) { |
|
184
|
|
|
return; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
$stylesSets = $config['styles']; |
|
188
|
|
|
|
|
189
|
|
|
foreach ($stylesSets as &$stylesSet) { |
|
190
|
|
|
foreach ($stylesSet as &$value) { |
|
191
|
|
|
$value = array_filter($value); |
|
192
|
|
|
} |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
$container |
|
196
|
|
|
->getDefinition('fos_ck_editor.styles_set_manager') |
|
197
|
|
|
->addMethodCall('setStylesSets', [$stylesSets]); |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* @param array $config |
|
202
|
|
|
* @param ContainerBuilder $container |
|
203
|
|
|
*/ |
|
204
|
|
|
private function registerTemplates(array $config, ContainerBuilder $container) |
|
205
|
|
|
{ |
|
206
|
|
|
if (!empty($config['templates'])) { |
|
207
|
|
|
$container |
|
208
|
|
|
->getDefinition('fos_ck_editor.template_manager') |
|
209
|
|
|
->addMethodCall('setTemplates', [$config['templates']]); |
|
210
|
|
|
} |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
/** |
|
214
|
|
|
* @param array $config |
|
215
|
|
|
* @param ContainerBuilder $container |
|
216
|
|
|
*/ |
|
217
|
|
|
private function registerToolbars(array $config, ContainerBuilder $container) |
|
218
|
|
|
{ |
|
219
|
|
|
$definition = $container->getDefinition('fos_ck_editor.toolbar_manager'); |
|
220
|
|
|
|
|
221
|
|
|
if (!empty($config['toolbars']['items'])) { |
|
222
|
|
|
$definition->addMethodCall('setItems', [$config['toolbars']['items']]); |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
if (!empty($config['toolbars']['configs'])) { |
|
226
|
|
|
$definition->addMethodCall('setToolbars', [$config['toolbars']['configs']]); |
|
227
|
|
|
} |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
/** |
|
231
|
|
|
* @param array $config |
|
232
|
|
|
* @param ContainerBuilder $container |
|
233
|
|
|
*/ |
|
234
|
|
|
private function registerFilebrowsers(array $config, ContainerBuilder $container) |
|
235
|
|
|
{ |
|
236
|
|
|
if (!empty($config['filebrowsers'])) { |
|
237
|
|
|
$container |
|
238
|
|
|
->getDefinition('fos_ck_editor.form.type') |
|
239
|
|
|
->addMethodCall('setFilebrowsers', [$config['filebrowsers']]); |
|
240
|
|
|
} |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
public function getAlias() |
|
244
|
|
|
{ |
|
245
|
|
|
return 'fos_ck_editor'; |
|
246
|
|
|
} |
|
247
|
|
|
} |
|
248
|
|
|
|