From 65d5d5d7b3fc186e894a6615c404dffab7beb2e3 Mon Sep 17 00:00:00 2001 From: Vidar Date: Fri, 5 Oct 2018 11:46:19 +0200 Subject: [PATCH 1/2] EZP-29328: Allow docbook tag "programlisting" (#2430) Consists of following g changes: * Allow docbook tag \ * Added support for ezxhtml:class attribute on \ docbook tag * Added attribute 'data-language' to ezxhtml5 schema * Added support for \ in docbook->xhtml transformation * Converting \ (docbook) to \ (html5) and vice versa for editor --- .../Compiler/RichTextHtml5ConverterPass.php | 23 +++++++--- .../Resources/config/fieldtype_services.yml | 17 +++++++- .../RichText/Converter/ProgramListing.php | 43 +++++++++++++++++++ .../Resources/schemas/docbook/ezpublish.rng | 2 +- .../schemas/ezxhtml5/output/changes.rst | 5 +++ .../schemas/ezxhtml5/output/ezxhtml5.xsd | 10 ++++- .../stylesheets/docbook/xhtml5/edit/core.xsl | 17 ++++++++ .../docbook/xhtml5/output/core.xsl | 17 ++++++++ .../stylesheets/xhtml5/edit/docbook.xsl | 18 ++++++++ .../Converter/Xslt/Xhtml5ToDocbookTest.php | 24 +++++++++++ .../_fixtures/docbook/033-programlisting.xml | 20 +++++++++ .../xhtml5/edit/033-programlisting.xml | 21 +++++++++ .../xhtml5/output/033-programlisting.xml | 21 +++++++++ 13 files changed, 230 insertions(+), 8 deletions(-) create mode 100644 eZ/Publish/Core/FieldType/RichText/Converter/ProgramListing.php create mode 100644 eZ/Publish/Core/FieldType/Tests/RichText/Converter/Xslt/_fixtures/docbook/033-programlisting.xml create mode 100644 eZ/Publish/Core/FieldType/Tests/RichText/Converter/Xslt/_fixtures/xhtml5/edit/033-programlisting.xml create mode 100644 eZ/Publish/Core/FieldType/Tests/RichText/Converter/Xslt/_fixtures/xhtml5/output/033-programlisting.xml diff --git a/eZ/Bundle/EzPublishCoreBundle/DependencyInjection/Compiler/RichTextHtml5ConverterPass.php b/eZ/Bundle/EzPublishCoreBundle/DependencyInjection/Compiler/RichTextHtml5ConverterPass.php index adae8cc9cc6..4b91a6dd210 100644 --- a/eZ/Bundle/EzPublishCoreBundle/DependencyInjection/Compiler/RichTextHtml5ConverterPass.php +++ b/eZ/Bundle/EzPublishCoreBundle/DependencyInjection/Compiler/RichTextHtml5ConverterPass.php @@ -11,6 +11,7 @@ use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; +use Symfony\Component\DependencyInjection\Definition; /** * Compiler pass for the RichText Aggregate converter tags. @@ -21,13 +22,25 @@ class RichTextHtml5ConverterPass implements CompilerPassInterface { public function process(ContainerBuilder $container) { - if (!$container->hasDefinition('ezpublish.fieldType.ezrichtext.converter.output.xhtml5')) { - return; + if ($container->hasDefinition('ezpublish.fieldType.ezrichtext.converter.output.xhtml5')) { + $html5OutputConverterDefinition = $container->getDefinition('ezpublish.fieldType.ezrichtext.converter.output.xhtml5'); + $taggedOutputServiceIds = $container->findTaggedServiceIds('ezpublish.ezrichtext.converter.output.xhtml5'); + $this->setConverterDefinitions($taggedOutputServiceIds, $html5OutputConverterDefinition); } - $html5ConverterDefinition = $container->getDefinition('ezpublish.fieldType.ezrichtext.converter.output.xhtml5'); - $taggedServiceIds = $container->findTaggedServiceIds('ezpublish.ezrichtext.converter.output.xhtml5'); + if ($container->hasDefinition('ezpublish.fieldType.ezrichtext.converter.input.xhtml5')) { + $html5InputConverterDefinition = $container->getDefinition('ezpublish.fieldType.ezrichtext.converter.input.xhtml5'); + $taggedInputServiceIds = $container->findTaggedServiceIds('ezpublish.ezrichtext.converter.input.xhtml5'); + $this->setConverterDefinitions($taggedInputServiceIds, $html5InputConverterDefinition); + } + } + /** + * @param array $taggedServiceIds + * @param Definition $converterDefinition + */ + protected function setConverterDefinitions(array $taggedServiceIds, Definition $converterDefinition) + { $convertersByPriority = array(); foreach ($taggedServiceIds as $id => $tags) { foreach ($tags as $tag) { @@ -37,7 +50,7 @@ public function process(ContainerBuilder $container) } if (count($convertersByPriority) > 0) { - $html5ConverterDefinition->setArguments( + $converterDefinition->setArguments( array($this->sortConverters($convertersByPriority)) ); } diff --git a/eZ/Bundle/EzPublishCoreBundle/Resources/config/fieldtype_services.yml b/eZ/Bundle/EzPublishCoreBundle/Resources/config/fieldtype_services.yml index 446d82e6bb4..ecb714ed1cc 100644 --- a/eZ/Bundle/EzPublishCoreBundle/Resources/config/fieldtype_services.yml +++ b/eZ/Bundle/EzPublishCoreBundle/Resources/config/fieldtype_services.yml @@ -18,6 +18,7 @@ parameters: ezpublish.fieldType.ezrichtext.converter.output.html5.class: eZ\Bundle\EzPublishCoreBundle\FieldType\RichText\Converter\Html5 ezpublish.fieldType.ezrichtext.converter.edit.html5.class: eZ\Bundle\EzPublishCoreBundle\FieldType\RichText\Converter\Html5Edit ezpublish.fieldType.ezrichtext.converter.input.html5.class: eZ\Bundle\EzPublishCoreBundle\FieldType\RichText\Converter\Html5Input + ezpublish.fieldType.ezrichtext.converter.programlisting.class: eZ\Publish\Core\FieldType\RichText\Converter\ProgramListing ezpublish.fieldType.ezrichtext.converter.link.class: eZ\Publish\Core\FieldType\RichText\Converter\Link ezpublish.fieldType.ezrichtext.converter.embed.class: eZ\Publish\Core\FieldType\RichText\Converter\Render\Embed ezpublish.fieldType.ezrichtext.converter.template.class: eZ\Publish\Core\FieldType\RichText\Converter\Render\Template @@ -116,11 +117,25 @@ services: - "http://ez.no/namespaces/ezpublish5/xhtml5/edit" - "%ezpublish.kernel.root_dir%/eZ/Publish/Core/FieldType/RichText/Resources/dtd/ezxhtml5_edit_html_character_entities.dtd" - ezpublish.fieldType.ezrichtext.converter.input.xhtml5: + ezpublish.fieldType.ezrichtext.converter.input.xhtml5.core: class: "%ezpublish.fieldType.ezrichtext.converter.input.html5.class%" arguments: - "%ezpublish.fieldType.ezrichtext.converter.input.xhtml5.resources%" - "@ezpublish.config.resolver" + tags: + - {name: ezpublish.ezrichtext.converter.input.xhtml5, priority: 50} + + # Note: should run before xsl transformation + ezpublish.fieldType.ezrichtext.converter.input.xhtml5.programlisting: + class: "%ezpublish.fieldType.ezrichtext.converter.programlisting.class%" + tags: + - {name: ezpublish.ezrichtext.converter.input.xhtml5, priority: 10} + + # Aggregate converter for XHTML5 input that other converters register to + # through service tags. + ezpublish.fieldType.ezrichtext.converter.input.xhtml5: + class: "%ezpublish.fieldType.ezrichtext.converter.aggregate.class%" + lazy: true ezpublish.fieldType.ezrichtext.converter.input.dispatcher: class: "%ezpublish.fieldType.ezrichtext.converter.dispatcher.class%" diff --git a/eZ/Publish/Core/FieldType/RichText/Converter/ProgramListing.php b/eZ/Publish/Core/FieldType/RichText/Converter/ProgramListing.php new file mode 100644 index 00000000000..408a142a866 --- /dev/null +++ b/eZ/Publish/Core/FieldType/RichText/Converter/ProgramListing.php @@ -0,0 +1,43 @@ +programlisting DocBook tag. + */ +class ProgramListing implements Converter +{ + /** + * CDATA's content cannot contain the sequence ']]>' as that will terminate the CDATA section. + * So, if the end sequence ']]>' appears in the string, we split the text into multiple CDATA sections. + * + * @param DOMDocument $document + * @return DOMDocument + */ + public function convert(DOMDocument $document) + { + $xpath = new DOMXPath($document); + $xpathExpression = '//ns:pre'; + $ns = $document->documentElement->namespaceURI; + $xpath->registerNamespace('ns', $ns); + $elements = $xpath->query($xpathExpression); + + foreach ($elements as $element) { + $element->textContent = str_replace(']]>', ']]]]>', $element->textContent); + } + + return $document; + } +} diff --git a/eZ/Publish/Core/FieldType/RichText/Resources/schemas/docbook/ezpublish.rng b/eZ/Publish/Core/FieldType/RichText/Resources/schemas/docbook/ezpublish.rng index a107d59f598..24abc063cbc 100644 --- a/eZ/Publish/Core/FieldType/RichText/Resources/schemas/docbook/ezpublish.rng +++ b/eZ/Publish/Core/FieldType/RichText/Resources/schemas/docbook/ezpublish.rng @@ -341,7 +341,6 @@ - @@ -668,6 +667,7 @@ + diff --git a/eZ/Publish/Core/FieldType/RichText/Resources/schemas/ezxhtml5/output/changes.rst b/eZ/Publish/Core/FieldType/RichText/Resources/schemas/ezxhtml5/output/changes.rst index c97fd360005..be9a1b650ef 100644 --- a/eZ/Publish/Core/FieldType/RichText/Resources/schemas/ezxhtml5/output/changes.rst +++ b/eZ/Publish/Core/FieldType/RichText/Resources/schemas/ezxhtml5/output/changes.rst @@ -12,3 +12,8 @@ Removed elements * * * + +Added attributes +================ + +* @data-language added for element
diff --git a/eZ/Publish/Core/FieldType/RichText/Resources/schemas/ezxhtml5/output/ezxhtml5.xsd b/eZ/Publish/Core/FieldType/RichText/Resources/schemas/ezxhtml5/output/ezxhtml5.xsd
index b48154b2faa..6cda2f9490c 100644
--- a/eZ/Publish/Core/FieldType/RichText/Resources/schemas/ezxhtml5/output/ezxhtml5.xsd
+++ b/eZ/Publish/Core/FieldType/RichText/Resources/schemas/ezxhtml5/output/ezxhtml5.xsd
@@ -249,13 +249,21 @@
     
   
 
+  
+    
+      
+        
+      
+    
+  
+
   
     
       
     
   
 
-  
+  
 
   
     
diff --git a/eZ/Publish/Core/FieldType/RichText/Resources/stylesheets/docbook/xhtml5/edit/core.xsl b/eZ/Publish/Core/FieldType/RichText/Resources/stylesheets/docbook/xhtml5/edit/core.xsl
index 24981f3495c..eeaec625d99 100644
--- a/eZ/Publish/Core/FieldType/RichText/Resources/stylesheets/docbook/xhtml5/edit/core.xsl
+++ b/eZ/Publish/Core/FieldType/RichText/Resources/stylesheets/docbook/xhtml5/edit/core.xsl
@@ -40,6 +40,23 @@
     
   
 
+  
+    
+      
+        
+          
+        
+      
+      
+        
+        
+          
+        
+      
+      
+    
+  
+
   
     
       
diff --git a/eZ/Publish/Core/FieldType/RichText/Resources/stylesheets/docbook/xhtml5/output/core.xsl b/eZ/Publish/Core/FieldType/RichText/Resources/stylesheets/docbook/xhtml5/output/core.xsl
index bffecfeac64..a9b98f4caf6 100644
--- a/eZ/Publish/Core/FieldType/RichText/Resources/stylesheets/docbook/xhtml5/output/core.xsl
+++ b/eZ/Publish/Core/FieldType/RichText/Resources/stylesheets/docbook/xhtml5/output/core.xsl
@@ -18,6 +18,23 @@
     
   
 
+  
+    
+      
+        
+          
+        
+      
+      
+        
+        
+          
+        
+      
+      
+    
+  
+
   
     
       
diff --git a/eZ/Publish/Core/FieldType/RichText/Resources/stylesheets/xhtml5/edit/docbook.xsl b/eZ/Publish/Core/FieldType/RichText/Resources/stylesheets/xhtml5/edit/docbook.xsl
index c06992c6450..fbfee61a76a 100644
--- a/eZ/Publish/Core/FieldType/RichText/Resources/stylesheets/xhtml5/edit/docbook.xsl
+++ b/eZ/Publish/Core/FieldType/RichText/Resources/stylesheets/xhtml5/edit/docbook.xsl
@@ -88,6 +88,24 @@
     
   
 
+  
+    
+      
+        
+          
+        
+      
+      
+        
+          
+        
+      
+      <![CDATA[
+      
+      ]]>
+    
+  
+
   
     
diff --git a/eZ/Publish/Core/FieldType/Tests/RichText/Converter/Xslt/Xhtml5ToDocbookTest.php b/eZ/Publish/Core/FieldType/Tests/RichText/Converter/Xslt/Xhtml5ToDocbookTest.php index c3c48ad5240..73567612444 100644 --- a/eZ/Publish/Core/FieldType/Tests/RichText/Converter/Xslt/Xhtml5ToDocbookTest.php +++ b/eZ/Publish/Core/FieldType/Tests/RichText/Converter/Xslt/Xhtml5ToDocbookTest.php @@ -8,6 +8,10 @@ */ namespace eZ\Publish\Core\FieldType\Tests\RichText\Converter\Xslt; +use eZ\Publish\Core\FieldType\RichText\Converter\Aggregate; +use eZ\Publish\Core\FieldType\RichText\Converter\ProgramListing; +use eZ\Publish\Core\FieldType\RichText\Converter\Xslt; + /** * Tests conversion from xhtml5 edit format to docbook. */ @@ -92,4 +96,24 @@ protected function getConversionValidationSchema() __DIR__ . '/../../../../RichText/Resources/schemas/docbook/docbook.iso.sch.xsl', ); } + + /** + * @return \eZ\Publish\Core\FieldType\RichText\Converter\Xslt + */ + protected function getConverter() + { + if ($this->converter === null) { + $this->converter = new Aggregate( + array( + new ProgramListing(), + new Xslt( + $this->getConversionTransformationStylesheet(), + $this->getCustomConversionTransformationStylesheets() + ), + ) + ); + } + + return $this->converter; + } } diff --git a/eZ/Publish/Core/FieldType/Tests/RichText/Converter/Xslt/_fixtures/docbook/033-programlisting.xml b/eZ/Publish/Core/FieldType/Tests/RichText/Converter/Xslt/_fixtures/docbook/033-programlisting.xml new file mode 100644 index 00000000000..0e8f4e6e25e --- /dev/null +++ b/eZ/Publish/Core/FieldType/Tests/RichText/Converter/Xslt/_fixtures/docbook/033-programlisting.xml @@ -0,0 +1,20 @@ +
+ and some more text here]]> + + + the php one: + รข'); + return 0; +}]]> + the php one with language attribute: + function foobar() +{ + thisIsSomePHPCode(); + return 0; +} +
diff --git a/eZ/Publish/Core/FieldType/Tests/RichText/Converter/Xslt/_fixtures/xhtml5/edit/033-programlisting.xml b/eZ/Publish/Core/FieldType/Tests/RichText/Converter/Xslt/_fixtures/xhtml5/edit/033-programlisting.xml new file mode 100644 index 00000000000..4de9a8a535c --- /dev/null +++ b/eZ/Publish/Core/FieldType/Tests/RichText/Converter/Xslt/_fixtures/xhtml5/edit/033-programlisting.xml @@ -0,0 +1,21 @@ + +
+
Literal with CNAME end sequence here : ]]> and some more text here
+
ordinary literal
+
more
+            complicated
+             literal
+              tag
+

the php one:

+
function foobar()
+{
+    thisIsSomePHPCode('string with special characters & < > â');
+    return 0;
+}
+

the php one with language attribute:

+
function foobar()
+{
+    thisIsSomePHPCode();
+    return 0;
+}
+
diff --git a/eZ/Publish/Core/FieldType/Tests/RichText/Converter/Xslt/_fixtures/xhtml5/output/033-programlisting.xml b/eZ/Publish/Core/FieldType/Tests/RichText/Converter/Xslt/_fixtures/xhtml5/output/033-programlisting.xml new file mode 100644 index 00000000000..245340a41b5 --- /dev/null +++ b/eZ/Publish/Core/FieldType/Tests/RichText/Converter/Xslt/_fixtures/xhtml5/output/033-programlisting.xml @@ -0,0 +1,21 @@ + +
+
Literal with CNAME end sequence here : ]]> and some more text here
+
ordinary literal
+
more
+            complicated
+             literal
+              tag
+

the php one:

+
function foobar()
+{
+    thisIsSomePHPCode('string with special characters & < > â');
+    return 0;
+}
+

the php one with language attribute:

+
function foobar()
+{
+    thisIsSomePHPCode();
+    return 0;
+}
+
From e2de624f7d5067fb3304036d7f88b10aff2d01e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Parafi=C5=84ski?= Date: Fri, 5 Oct 2018 11:48:55 +0200 Subject: [PATCH 2/2] EZP-29695: Option "Default content availability" on content types not working (#2462) --- eZ/Publish/Core/Repository/ContentService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eZ/Publish/Core/Repository/ContentService.php b/eZ/Publish/Core/Repository/ContentService.php index b64b702dde1..08d87a847cc 100644 --- a/eZ/Publish/Core/Repository/ContentService.php +++ b/eZ/Publish/Core/Repository/ContentService.php @@ -550,7 +550,7 @@ public function createContent(APIContentCreateStruct $contentCreateStruct, array } if ($contentCreateStruct->alwaysAvailable === null) { - $contentCreateStruct->alwaysAvailable = false; + $contentCreateStruct->alwaysAvailable = $contentCreateStruct->contentType->defaultAlwaysAvailable ?: false; } $contentCreateStruct->contentType = $this->repository->getContentTypeService()->loadContentType(