Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

RichText.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\Parser\FieldType;
8
9 use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\Parser\AbstractFieldTypeParser;
10 use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware\ContextualizerInterface;
11 use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\EzPublishCoreExtension;
12 use Symfony\Component\Config\Definition\Builder\NodeBuilder;
13 use Symfony\Component\Config\Definition\Builder\ScalarNodeDefinition;
14 use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
15 use Symfony\Component\DependencyInjection\ContainerInterface;
16
20 class RichText extends AbstractFieldTypeParser
21 {
28 public function getFieldTypeIdentifier()
29 {
30 return 'ezrichtext';
31 }
32
38 public function addFieldTypeSemanticConfig(NodeBuilder $nodeBuilder)
39 {
40 // for BC setup deprecated configuration
41 $this->setupDeprecatedConfiguration($nodeBuilder);
42
43 $nodeBuilder
44 ->arrayNode('embed')
45 ->info('RichText embed tags configuration.')
46 ->children()
47 ->arrayNode('content')
48 ->info('Configuration for RichText block-level Content embed tags.')
49 ->children()
50 ->append(
51 $this->getTemplateNodeDefinition(
52 'Template used for rendering RichText block-level Content embed tags.',
53 'MyBundle:FieldType/RichText/embed:content.html.twig'
54 )
55 )
56 ->variableNode('config')
57 ->info('Embed configuration, arbitrary configuration is allowed here.')
58 ->end()
59 ->end()
60 ->end()
61 ->arrayNode('content_denied')
62 ->info('Configuration for RichText block-level Content embed tags when embed is not permitted.')
63 ->children()
64 ->append(
65 $this->getTemplateNodeDefinition(
66 'Template used for rendering RichText block-level Content embed tags when embed is not permitted.',
67 'MyBundle:FieldType/RichText/embed:content_denied.html.twig'
68 )
69 )
70 ->variableNode('config')
71 ->info('Embed configuration, arbitrary configuration is allowed here.')
72 ->end()
73 ->end()
74 ->end()
75 ->arrayNode('content_inline')
76 ->info('Configuration for RichText inline-level Content embed tags.')
77 ->children()
78 ->append(
79 $this->getTemplateNodeDefinition(
80 'Template used for rendering RichText inline-level Content embed tags.',
81 'MyBundle:FieldType/RichText/embed:content_inline.html.twig'
82 )
83 )
84 ->variableNode('config')
85 ->info('Embed configuration, arbitrary configuration is allowed here.')
86 ->end()
87 ->end()
88 ->end()
89 ->arrayNode('content_inline_denied')
90 ->info('Configuration for RichText inline-level Content embed tags when embed is not permitted.')
91 ->children()
92 ->append(
93 $this->getTemplateNodeDefinition(
94 'Template used for rendering RichText inline-level Content embed tags when embed is not permitted.',
95 'MyBundle:FieldType/RichText/embed:content_inline_denied.html.twig'
96 )
97 )
98 ->variableNode('config')
99 ->info('Embed configuration, arbitrary configuration is allowed here.')
100 ->end()
101 ->end()
102 ->end()
103 ->arrayNode('location')
104 ->info('Configuration for RichText block-level Location embed tags.')
105 ->children()
106 ->append(
107 $this->getTemplateNodeDefinition(
108 'Template used for rendering RichText block-level Location embed tags.',
109 'MyBundle:FieldType/RichText/embed:location.html.twig'
110 )
111 )
112 ->variableNode('config')
113 ->info('Embed configuration, arbitrary configuration is allowed here.')
114 ->end()
115 ->end()
116 ->end()
117 ->arrayNode('location_denied')
118 ->info('Configuration for RichText block-level Location embed tags when embed is not permitted.')
119 ->children()
120 ->append(
121 $this->getTemplateNodeDefinition(
122 'Template used for rendering RichText block-level Location embed tags when embed is not permitted.',
123 'MyBundle:FieldType/RichText/embed:location_denied.html.twig'
124 )
125 )
126 ->variableNode('config')
127 ->info('Embed configuration, arbitrary configuration is allowed here.')
128 ->end()
129 ->end()
130 ->end()
131 ->arrayNode('location_inline')
132 ->info('Configuration for RichText inline-level Location embed tags.')
133 ->children()
134 ->append(
135 $this->getTemplateNodeDefinition(
136 'Template used for rendering RichText inline-level Location embed tags.',
137 'MyBundle:FieldType/RichText/embed:location_inline.html.twig'
138 )
139 )
140 ->variableNode('config')
141 ->info('Embed configuration, arbitrary configuration is allowed here.')
142 ->end()
143 ->end()
144 ->end()
145 ->arrayNode('location_inline_denied')
146 ->info('Configuration for RichText inline-level Location embed tags when embed is not permitted.')
147 ->children()
148 ->append(
149 $this->getTemplateNodeDefinition(
150 'Template used for rendering RichText inline-level Location embed tags when embed is not permitted.',
151 'MyBundle:FieldType/RichText/embed:location_inline_denied.html.twig'
152 )
153 )
154 ->variableNode('config')
155 ->info('Embed configuration, arbitrary configuration is allowed here.')
156 ->end()
157 ->end()
158 ->end()
159 ->end()
160 ->end();
161
162 // RichText Custom Tags configuration (list of Custom Tags enabled for current SiteAccess scope)
163 $nodeBuilder
164 ->arrayNode('custom_tags')
165 ->info('List of RichText Custom Tags enabled for the current scope. The Custom Tags must be defined in ezpublish.ezrichtext.custom_tags Node.')
166 ->scalarPrototype()->end()
167 ->end();
168
169 // RichText Custom Styles configuration (list of Custom Styles enabled for current SiteAccess scope)
170 $nodeBuilder
171 ->arrayNode('custom_styles')
172 ->info('List of RichText Custom Styles enabled for the current scope. The Custom Styles must be defined in ezpublish.ezrichtext.custom_styles Node.')
173 ->scalarPrototype()->end()
174 ->end();
175 }
176
183 protected function getTemplateNodeDefinition($info, $example)
184 {
185 $templateNodeDefinition = new ScalarNodeDefinition('template');
186 $templateNodeDefinition
187 ->info($info)
188 ->example($example)
189 ->isRequired()
190 ->cannotBeEmpty();
191
192 return $templateNodeDefinition;
193 }
194
195 public function mapConfig(array &$scopeSettings, $currentScope, ContextualizerInterface $contextualizer)
196 {
197 if (!empty($scopeSettings['fieldtypes'])) {
198 // Workaround to be able to use Contextualizer::mapConfigArray() which only supports first level entries.
199 if (isset($scopeSettings['fieldtypes']['ezrichtext']['output_custom_tags'])) {
200 $scopeSettings['fieldtypes.ezrichtext.output_custom_xsl'] = $scopeSettings['fieldtypes']['ezrichtext']['output_custom_tags'];
201 unset($scopeSettings['fieldtypes']['ezrichtext']['output_custom_tags']);
202 }
203
204 if (isset($scopeSettings['fieldtypes']['ezrichtext']['edit_custom_tags'])) {
205 $scopeSettings['fieldtypes.ezrichtext.edit_custom_xsl'] = $scopeSettings['fieldtypes']['ezrichtext']['edit_custom_tags'];
206 unset($scopeSettings['fieldtypes']['ezrichtext']['edit_custom_tags']);
207 }
208
209 if (isset($scopeSettings['fieldtypes']['ezrichtext']['input_custom_tags'])) {
210 $scopeSettings['fieldtypes.ezrichtext.input_custom_xsl'] = $scopeSettings['fieldtypes']['ezrichtext']['input_custom_tags'];
211 unset($scopeSettings['fieldtypes']['ezrichtext']['input_custom_tags']);
212 }
213
214 if (isset($scopeSettings['fieldtypes']['ezrichtext']['custom_tags'])) {
215 $this->validateCustomTagsConfiguration(
216 $contextualizer->getContainer(),
217 $scopeSettings['fieldtypes']['ezrichtext']['custom_tags']
218 );
219 $contextualizer->setContextualParameter(
220 'fieldtypes.ezrichtext.custom_tags',
221 $currentScope,
222 $scopeSettings['fieldtypes']['ezrichtext']['custom_tags']
223 );
224 }
225 if (isset($scopeSettings['fieldtypes']['ezrichtext']['custom_styles'])) {
226 $this->validateCustomStylesConfiguration(
227 $contextualizer->getContainer(),
228 $scopeSettings['fieldtypes']['ezrichtext']['custom_styles']
229 );
230 $contextualizer->setContextualParameter(
231 'fieldtypes.ezrichtext.custom_styles',
232 $currentScope,
233 $scopeSettings['fieldtypes']['ezrichtext']['custom_styles']
234 );
235 }
236
237 if (isset($scopeSettings['fieldtypes']['ezrichtext']['tags'])) {
238 foreach ($scopeSettings['fieldtypes']['ezrichtext']['tags'] as $name => $tagSettings) {
239 $contextualizer->setContextualParameter(
240 "fieldtypes.ezrichtext.tags.{$name}",
241 $currentScope,
242 $scopeSettings['fieldtypes']['ezrichtext']['tags'][$name]
243 );
244 }
245 }
246
247 if (isset($scopeSettings['fieldtypes']['ezrichtext']['embed'])) {
248 foreach ($scopeSettings['fieldtypes']['ezrichtext']['embed'] as $type => $embedSettings) {
249 $contextualizer->setContextualParameter(
250 "fieldtypes.ezrichtext.embed.{$type}",
251 $currentScope,
252 $scopeSettings['fieldtypes']['ezrichtext']['embed'][$type]
253 );
254 }
255 }
256 }
257 }
258
259 public function postMap(array $config, ContextualizerInterface $contextualizer)
260 {
261 $contextualizer->mapConfigArray('fieldtypes.ezrichtext.output_custom_xsl', $config);
262 $contextualizer->mapConfigArray('fieldtypes.ezrichtext.edit_custom_xsl', $config);
263 $contextualizer->mapConfigArray('fieldtypes.ezrichtext.input_custom_xsl', $config);
264 }
265
272 private function validateCustomTagsConfiguration(
273 ContainerInterface $container,
274 array $enabledCustomTags
275 ) {
276 $definedCustomTags = array_keys(
277 $container->getParameter(EzPublishCoreExtension::RICHTEXT_CUSTOM_TAGS_PARAMETER)
278 );
279 foreach ($enabledCustomTags as $customTagName) {
280 if (!in_array($customTagName, $definedCustomTags)) {
281 throw new InvalidConfigurationException(
282 "Unknown RichText Custom Tag '{$customTagName}'"
283 );
284 }
285 }
286 }
287
294 private function validateCustomStylesConfiguration(
295 ContainerInterface $container,
296 array $enabledCustomStyles
297 ) {
298 $definedCustomStyles = array_keys(
299 $container->getParameter(EzPublishCoreExtension::RICHTEXT_CUSTOM_STYLES_PARAMETER)
300 );
301 foreach ($enabledCustomStyles as $customStyleName) {
302 if (!in_array($customStyleName, $definedCustomStyles)) {
303 throw new InvalidConfigurationException(
304 "Unknown RichText Custom Style '{$customStyleName}'"
305 );
306 }
307 }
308 }
309
317 private function setupDeprecatedConfiguration(NodeBuilder $nodeBuilder)
318 {
319 $nodeBuilder
320 ->arrayNode('output_custom_tags')
321 ->setDeprecated('DEPRECATED. Configure custom tags using custom_tags node')
322 ->info('Custom XSL stylesheets to use for RichText transformation to HTML5. Useful for "custom tags".')
323 ->example(
324 [
325 'path' => '%kernel.root_dir%/../src/Acme/TestBundle/Resources/myTag.xsl',
326 'priority' => 10,
327 ]
328 )
329 ->prototype('array')
330 ->children()
331 ->scalarNode('path')
332 ->info('Path of the XSL stylesheet to load.')
333 ->isRequired()
334 ->end()
335 ->integerNode('priority')
336 ->info('Priority in the loading order. A high value will have higher precedence in overriding XSL templates.')
337 ->defaultValue(0)
338 ->end()
339 ->end()
340 ->end()
341 ->end()
342 ->arrayNode('edit_custom_tags')
343 ->setDeprecated('DEPRECATED. Configure custom tags using custom_tags node')
344 ->info('Custom XSL stylesheets to use for RichText transformation to HTML5. Useful for "custom tags".')
345 ->example(
346 [
347 'path' => '%kernel.root_dir%/../src/Acme/TestBundle/Resources/myTag.xsl',
348 'priority' => 10,
349 ]
350 )
351 ->prototype('array')
352 ->children()
353 ->scalarNode('path')
354 ->info('Path of the XSL stylesheet to load.')
355 ->isRequired()
356 ->end()
357 ->integerNode('priority')
358 ->info('Priority in the loading order. A high value will have higher precedence in overriding XSL templates.')
359 ->defaultValue(0)
360 ->end()
361 ->end()
362 ->end()
363 ->end()
364 ->arrayNode('input_custom_tags')
365 ->setDeprecated('DEPRECATED. Configure custom tags using custom_tags node')
366 ->info('Custom XSL stylesheets to use for RichText transformation to HTML5. Useful for "custom tags".')
367 ->example(
368 [
369 'path' => '%kernel.root_dir%/../src/Acme/TestBundle/Resources/myTag.xsl',
370 'priority' => 10,
371 ]
372 )
373 ->prototype('array')
374 ->children()
375 ->scalarNode('path')
376 ->info('Path of the XSL stylesheet to load.')
377 ->isRequired()
378 ->end()
379 ->integerNode('priority')
380 ->info('Priority in the loading order. A high value will have higher precedence in overriding XSL templates.')
381 ->defaultValue(0)
382 ->end()
383 ->end()
384 ->end()
385 ->end()
386 ->arrayNode('tags')
387 ->setDeprecated('DEPRECATED. Configure custom tags using custom_tags node')
388 ->info('RichText template tags configuration.')
389 ->useAttributeAsKey('key')
390 ->normalizeKeys(false)
391 ->prototype('array')
392 ->info(
393 "Name of RichText template tag.\n" .
394 "'default' and 'default_inline' tag names are reserved for fallback."
395 )
396 ->example('math_equation')
397 ->children()
398 ->append(
399 $this->getTemplateNodeDefinition(
400 'Template used for rendering RichText template tag.',
401 'MyBundle:FieldType/RichText/tag:math_equation.html.twig'
402 )
403 )
404 ->variableNode('config')
405 ->info('Tag configuration, arbitrary configuration is allowed here.')
406 ->end()
407 ->end()
408 ->end()
409 ->end()
410 ;
411 }
412 }
eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\Parser\AbstractFieldTypeParser
Abstract parser class that field type parsers need to extend in order to receive NodeBuilder at Node ...
Definition: AbstractFieldTypeParser.php:18
eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\Parser\FieldType\RichText
Configuration parser handling RichText field type related config.
Definition: RichText.php:21
eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\Parser\FieldType\RichText\setupDeprecatedConfiguration
setupDeprecatedConfiguration(NodeBuilder $nodeBuilder)
Add BC setup for deprecated configuration.
Definition: RichText.php:317
eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\Parser\FieldType\RichText\addFieldTypeSemanticConfig
addFieldTypeSemanticConfig(NodeBuilder $nodeBuilder)
Adds semantic configuration definition.
Definition: RichText.php:38
eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\Parser\FieldType\RichText\validateCustomTagsConfiguration
validateCustomTagsConfiguration(ContainerInterface $container, array $enabledCustomTags)
Validate SiteAccess-defined Custom Tags configuration against global one.
Definition: RichText.php:272
eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\Parser\FieldType\RichText\getFieldTypeIdentifier
getFieldTypeIdentifier()
Returns the fieldType identifier the config parser works for.
Definition: RichText.php:28
eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\Parser\FieldType\RichText\getTemplateNodeDefinition
getTemplateNodeDefinition($info, $example)
Definition: RichText.php:183
eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\Parser\FieldType\RichText\postMap
postMap(array $config, ContextualizerInterface $contextualizer)
This method is called by the ConfigurationProcessor after looping over available scopes.
Definition: RichText.php:259
eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\Parser\FieldType\RichText\mapConfig
mapConfig(array &$scopeSettings, $currentScope, ContextualizerInterface $contextualizer)
Does semantic config to internal container parameters mapping for $currentScope.
Definition: RichText.php:195
eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\Parser\FieldType\RichText\validateCustomStylesConfiguration
validateCustomStylesConfiguration(ContainerInterface $container, array $enabledCustomStyles)
Validate SiteAccess-defined Custom Styles configuration against global one.
Definition: RichText.php:294
eZ\Bundle\EzPublishCoreBundle\DependencyInjection\EzPublishCoreExtension
Definition: EzPublishCoreExtension.php:29
eZ\Bundle\EzPublishCoreBundle\DependencyInjection\EzPublishCoreExtension\RICHTEXT_CUSTOM_TAGS_PARAMETER
const RICHTEXT_CUSTOM_TAGS_PARAMETER
Definition: EzPublishCoreExtension.php:31
eZ\Bundle\EzPublishCoreBundle\DependencyInjection\EzPublishCoreExtension\RICHTEXT_CUSTOM_STYLES_PARAMETER
const RICHTEXT_CUSTOM_STYLES_PARAMETER
Definition: EzPublishCoreExtension.php:30
eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware\ContextualizerInterface
Definition: ContextualizerInterface.php:12
eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware\ContextualizerInterface\setContextualParameter
setContextualParameter($parameterName, $scope, $value)
Defines a contextual parameter in the container for given scope in current namespace.
eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware\ContextualizerInterface\mapConfigArray
mapConfigArray($id, array $config, $options=0)
Maps semantic array settings to internal format, and merges them between scopes.
eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware\ContextualizerInterface\getContainer
getContainer()
eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\Parser\FieldType
Definition: ImageAsset.php:9
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.