Skip to content

Commit

Permalink
EZP-31231: Fixed storing align and anchor attributes for custom styles (
Browse files Browse the repository at this point in the history
  • Loading branch information
Bartek authored Oct 7, 2020
1 parent bd87be8 commit e10fecc
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 11 deletions.
23 changes: 21 additions & 2 deletions src/lib/eZ/RichText/Converter/Render/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ protected function processTemplate(DOMDocument $document, DOMXPath $xpath, DOMEl
}
$parameters['content'] = !empty($innerContent) ? $innerContent : null;

if ($template->hasAttribute('ezxhtml:align')) {
$parameters['align'] = $template->getAttribute('ezxhtml:align');
foreach ($this->getAttributesMap() as $attribute => $param) {
if ($template->hasAttribute($attribute)) {
$parameters[$param] = $template->getAttribute($attribute);
}
}

$content = $this->renderer->renderTemplate(
Expand All @@ -115,6 +117,23 @@ protected function processTemplate(DOMDocument $document, DOMXPath $xpath, DOMEl
}
}

/**
* Provides attributes map in format:
* [
* attribute => param,
* ...
* ].
*
* @return string[]
*/
protected function getAttributesMap(): array
{
return [
'ezxhtml:align' => 'align',
'xml:id' => 'id',
];
}

/**
* Returns XML fragment string for given converted $node.
*
Expand Down
3 changes: 3 additions & 0 deletions src/lib/eZ/RichText/Resources/schemas/docbook/ezpublish.rng
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,9 @@
<optional>
<ref name="ez.xhtml.align"/>
</optional>
<optional>
<ref name="db.xml.id.attribute"/>
</optional>
<ref name="ez.template.attributes.inline"/>
</define>
<define name="ez.template.type">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,17 @@
<xsl:value-of select="@ezxhtml:class"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="@ezxhtml:align">
<xsl:if test="@xml:id">
<xsl:attribute name="id">
<xsl:value-of select="@xml:id"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="@ezxhtml:align and @type='style'">
<xsl:attribute name="style">
<xsl:value-of select="concat( 'text-align:', @ezxhtml:align, ';' )"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="@ezxhtml:align and not(@type='style')">
<xsl:attribute name="data-ezalign">
<xsl:value-of select="@ezxhtml:align"/>
</xsl:attribute>
Expand Down
18 changes: 18 additions & 0 deletions src/lib/eZ/RichText/Resources/stylesheets/xhtml5/edit/docbook.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,24 @@
<xsl:value-of select="@class"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="@id">
<xsl:attribute name="xml:id">
<xsl:value-of select="@id"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="contains( @style, 'text-align:' )">
<xsl:variable name="textAlign">
<xsl:call-template name="extractStyleValue">
<xsl:with-param name="style" select="@style"/>
<xsl:with-param name="property" select="'text-align'"/>
</xsl:call-template>
</xsl:variable>
<xsl:if test="$textAlign != ''">
<xsl:attribute name="ezxhtml:align">
<xsl:value-of select="$textAlign"/>
</xsl:attribute>
</xsl:if>
</xsl:if>
<xsl:if test="@data-ezalign">
<xsl:attribute name="ezxhtml:align">
<xsl:value-of select="@data-ezalign"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
xmlns:ezxhtml="http://ez.no/xmlns/ezpublish/docbook/xhtml"
xmlns:ezcustom="http://ez.no/xmlns/ezpublish/docbook/custom"
version="5.0-variant ezpublish-1.0">
<eztemplate name="factbox" ezxhtml:class="templateClass" ezxhtml:align="left">
<eztemplate name="factbox" ezxhtml:class="templateClass" ezxhtml:align="left" xml:id="template">
<ezcontent>
<eztemplate name="externalimage" ezxhtml:class="templateClass2" ezxhtml:align="right">
<eztemplate name="externalimage" ezxhtml:class="templateClass2" ezxhtml:align="right" xml:id="nested-template">
<ezconfig>
<ezvalue key="src">
http://upload.wikimedia.org/wikipedia/commons/c/c6/R-S_mk2.gif
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<section xmlns="http://ez.no/namespaces/ezpublish5/xhtml5/edit">
<div data-ezelement="eztemplate" data-eztype="style" data-ezname="highlighted_block" data-ezalign="left">Highlighted block with "left" align.</div>
<div data-ezelement="eztemplate" data-eztype="style" data-ezname="highlighted_block" data-ezalign="right">Highlighted block with "right" align.</div>
<div data-ezelement="eztemplate" data-eztype="style" data-ezname="highlighted_block" data-ezalign="center">Highlighted block with "center" align.</div>
<div data-ezelement="eztemplate" data-eztype="style" data-ezname="highlighted_block" style="text-align:left;">Highlighted block with "left" align.</div>
<div data-ezelement="eztemplate" data-eztype="style" data-ezname="highlighted_block" style="text-align:right;">Highlighted block with "right" align.</div>
<div data-ezelement="eztemplate" data-eztype="style" data-ezname="highlighted_block" style="text-align:center;">Highlighted block with "center" align.</div>
<div data-ezelement="eztemplate" data-eztype="style" data-ezname="highlighted_block">Highlighted block with multiple lines<br/>Highlighted block with multiple lines<br/>Highlighted block with multiple lines</div>
<div data-ezelement="eztemplate" data-eztype="style" data-ezname="highlighted_block">Highlighted block with multiple lines and emphasis<br/><strong>Highlighted block with multiple lines and emphasis</strong><br/>Highlighted block with multiple lines and emphasis</div>
</section>
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<section xmlns="http://ez.no/namespaces/ezpublish5/xhtml5/edit">
<div data-ezelement="eztemplate" data-ezname="factbox" class="templateClass" data-ezalign="left">
<div data-ezelement="eztemplate" data-ezname="factbox" class="templateClass" id="template" data-ezalign="left">
<div data-ezelement="ezcontent">
<div data-ezelement="eztemplate" data-ezname="externalimage" class="templateClass2"
data-ezalign="right">
<div data-ezelement="eztemplate" data-ezname="externalimage" class="templateClass2" data-ezalign="right" id="nested-template">
<span data-ezelement="ezconfig">
<span data-ezelement="ezvalue" data-ezvalue-key="src">
http://upload.wikimedia.org/wikipedia/commons/c/c6/R-S_mk2.gif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
</param>
<param name="content"/>
<param name="align">right</param>
<param name="id">nested-template</param>
</template-output>
</section>
</param>
<param name="align">left</param>
<param name="id">template</param>
</template-output>
</section>

0 comments on commit e10fecc

Please sign in to comment.