Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EZP-29634: ezxmltext -> richtext conversion : <custom> inside <section> #76

Merged
merged 1 commit into from
Oct 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions lib/FieldType/XmlText/Converter/RichText.php
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,38 @@ protected function writeWarningOnNonSupportedLiterals(DOMDocument $document, $co
}
}

/**
* @param DOMDocument $document
* @param null|int $contentFieldId
*/
protected function writeWarningOnNonSupportedCustomTags(DOMDocument $document, $contentFieldId)
{
$xpath = new DOMXPath($document);

$xpathExpression = '//custom';

$elements = $xpath->query($xpathExpression);

foreach ($elements as $element) {
$customTagName = $element->getAttribute('name');
$parent = $element->parentNode;
$blockCustomTag = ($parent->localName === 'paragraph' && $parent->hasAttribute('ez-temporary')) || $parent->localName === 'section';

// These legacy custom tags are not custom tags in richtext
if (in_array($customTagName, ['quote', 'underline', 'strike', 'sub', 'sup'])) {
continue;
}

if (!$blockCustomTag) {
$this->log(LogLevel::WARNING, "Inline custom tag '$customTagName' not supported by editor at the moment. You'll not be able to edit content correctly in editor where contentobject_attribute.id=$contentFieldId");
}

if ($parent->localName === 'section') {
$this->log(LogLevel::WARNING, "Custom tag '$customTagName' converted to block custom tag. It might have been inline custom tag in legacy DB where contentobject_attribute.id=$contentFieldId");
}
}
}

/**
* Before calling this function, make sure you are logged in as admin, or at least have access to all the objects
* being embedded and linked to in the $inputDocument.
Expand Down Expand Up @@ -560,6 +592,7 @@ public function convert(DOMDocument $inputDocument, $checkDuplicateIds = false,
);
throw $e;
}
$this->writeWarningOnNonSupportedCustomTags($inputDocument, $contentFieldId);
if ($checkDuplicateIds) {
$this->reportNonUniqueIds($convertedDocument, $contentFieldId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,31 +50,7 @@
</xsl:element>
</xsl:template>

<xsl:template match="literal">
<xsl:choose>
<xsl:when test="@class = 'html'">
<xsl:element name="eztemplate">
<xsl:attribute name="name">
<xsl:value-of select="'rawhtml'"/>
</xsl:attribute>
<xsl:element name="ezcontent">
<xsl:value-of select="./text()"/>
</xsl:element>
<xsl:if test="@*[namespace-uri() = 'http://ez.no/namespaces/ezpublish3/custom/' and not( local-name() = 'class' )]">
<xsl:element name="ezconfig">
<xsl:for-each select="@*[namespace-uri() = 'http://ez.no/namespaces/ezpublish3/custom/' and not( local-name() = 'class' )]">
<xsl:call-template name="addHashValue">
<xsl:with-param name="attribute" select="current()"/>
</xsl:call-template>
</xsl:for-each>
</xsl:element>
</xsl:if>
</xsl:element>
</xsl:when>
</xsl:choose>
</xsl:template>

<xsl:template match="paragraph[@ez-temporary]/custom">
<xsl:template match="paragraph[@ez-temporary]/custom|section/custom">
<xsl:element name="eztemplate" namespace="http://docbook.org/ns/docbook">
<xsl:attribute name="name">
<xsl:value-of select="@name"/>
Expand Down Expand Up @@ -106,6 +82,30 @@
</xsl:element>
</xsl:template>

<xsl:template match="literal">
<xsl:choose>
<xsl:when test="@class = 'html'">
<xsl:element name="eztemplate">
<xsl:attribute name="name">
<xsl:value-of select="'rawhtml'"/>
</xsl:attribute>
<xsl:element name="ezcontent">
<xsl:value-of select="./text()"/>
</xsl:element>
<xsl:if test="@*[namespace-uri() = 'http://ez.no/namespaces/ezpublish3/custom/' and not( local-name() = 'class' )]">
<xsl:element name="ezconfig">
<xsl:for-each select="@*[namespace-uri() = 'http://ez.no/namespaces/ezpublish3/custom/' and not( local-name() = 'class' )]">
<xsl:call-template name="addHashValue">
<xsl:with-param name="attribute" select="current()"/>
</xsl:call-template>
</xsl:for-each>
</xsl:element>
</xsl:if>
</xsl:element>
</xsl:when>
</xsl:choose>
</xsl:template>

<xsl:template match="section">
<xsl:choose>
<xsl:when test="count(ancestor-or-self::section) &gt; 1">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<section
xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/"
xmlns:image="http://ez.no/namespaces/ezpublish3/image/"
xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/">
<section>
<custom name="linebreak"/>
</section>
<!-- xmlns:tmp="http://ez.no/namespaces/ezpublish3/temporary/"-->
<paragraph xmlns:tmp="http://ez.no/namespaces/ezpublish3/temporary/">
<custom name="mycustomtag" custom:class="templateClass" custom:align="left" custom:title="foobar">
custom tag content
</custom>
</paragraph>
</section>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<section
xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/"
xmlns:image="http://ez.no/namespaces/ezpublish3/image/"
xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/">
<header>Advisers:
<custom name="linebreak"/>Foobar Corp.</header>
</section>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
warning:Custom tag 'linebreak' converted to block custom tag. It might have been inline custom tag in legacy DB where contentobject_attribute.id=
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
warning:Inline custom tag 'linebreak' not supported by editor at the moment. You'll not be able to edit content correctly in editor where contentobject_attribute.id=
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<section
xmlns="http://docbook.org/ns/docbook"
xmlns:ezcustom="http://ez.no/xmlns/ezpublish/docbook/custom"
xmlns:ezxhtml="http://ez.no/xmlns/ezpublish/docbook/xhtml"
xmlns:xlink="http://www.w3.org/1999/xlink" version="5.0-variant ezpublish-1.0">
<eztemplate name="linebreak"/>
<eztemplate name="mycustomtag" ezxhtml:align="left" ezxhtml:class="templateClass">
<ezcontent>
custom tag content
</ezcontent>
<ezconfig>
<ezvalue key="title">foobar</ezvalue>
</ezconfig>
</eztemplate>
</section>

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<section
xmlns="http://docbook.org/ns/docbook"
xmlns:ezcustom="http://ez.no/xmlns/ezpublish/docbook/custom"
xmlns:ezxhtml="http://ez.no/xmlns/ezpublish/docbook/xhtml"
xmlns:xlink="http://www.w3.org/1999/xlink" version="5.0-variant ezpublish-1.0">
<title ezxhtml:level="2">Advisers:
<eztemplateinline name="linebreak"/>Foobar Corp.</title>
</section>