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-29554: As an editor, I want to be able to apply custom styles to part of my text #2427
EZP-29554: As an editor, I want to be able to apply custom styles to part of my text #2427
Conversation
} | ||
|
||
if (!$this->templateEngine->exists($templateName)) { | ||
if (isset($this->logger)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick, how about a dedicate method for this logging part in order to avoid some dupe code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree.
I think i would be best also to move each "render" to dedicated class as this one keep growing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick, how about a dedicate method for this logging part in order to avoid some dupe code?
Actually, that's not what we do nowadays.
Please change in the constructor:
$this->logger = $logger;
to
$this->logger = $logger ?? new NullLogger();
and then you can skip if (isset($this->logger))
.
I think i would be best also to move each "render" to dedicated class as this one keep growing.
Yes. If you're up to it you can do it, but as this is not necessarily in the scope of this PR, for now it can stay like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks okay-ish. A lot of work, good job @florianalexandre 👍
First and foremost I miss test cases:
-
You need to create proper fixtures in the
eZ/Publish/Core/FieldType/Tests/RichText/Converter/Xslt/_fixtures
directory so we can see in a clear way what XSL transforms here. -
There is also missing Style Converter test in the
eZ/Publish/Core/FieldType/Tests/RichText/Converter/Render
directory.
What worries me a bit is a lot of failing tests on Travis. It needs to be addressed also before we proceed. In case of REST/Behat jobs just a rebase might be needed.
Other requests:
@@ -0,0 +1 @@ | |||
<div class="{% if align is defined %}align-{{ align }}{% endif %} style-{{ name }}">{% spaceless %}{{ content|raw }}{% endspaceless %}</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing new line at the end of the file
@@ -0,0 +1 @@ | |||
<span class="style-{{ name }}">{% spaceless %}{{ content|raw }}{% endspaceless %}</span> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here - missing newline (you can only see it on github preview probably).
} | ||
|
||
if (!$this->templateEngine->exists($templateName)) { | ||
if (isset($this->logger)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick, how about a dedicate method for this logging part in order to avoid some dupe code?
Actually, that's not what we do nowadays.
Please change in the constructor:
$this->logger = $logger;
to
$this->logger = $logger ?? new NullLogger();
and then you can skip if (isset($this->logger))
.
I think i would be best also to move each "render" to dedicated class as this one keep growing.
Yes. If you're up to it you can do it, but as this is not necessarily in the scope of this PR, for now it can stay like this.
@@ -627,6 +627,34 @@ | |||
</xsl:element> | |||
</xsl:template> | |||
|
|||
<!-- Custom template tag code --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copy-paste typo I guess, should be Custom style tag code
, right? (the "template" doesn't refer to XSL markup but to eZ templates which are more widely known as Custom Tags)
@@ -622,4 +622,27 @@ | |||
<xsl:value-of select="translate( substring-before( substring-after( concat( substring-after( $style, $property ), ';' ), ':' ), ';' ), ' ', '' )"/> | |||
</xsl:template> | |||
|
|||
<xsl:template match="ezxhtml5:div[@data-style]"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, this is about our custom styles, not <div style
attribute, right? If so, then I'd prefer to see here ezstyle
.
This comment has been minimized.
This comment has been minimized.
2d7f38f
to
cf7a3a9
Compare
Fixed requested change from @alongosz and failed tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lot of parameters and return values could be typehinted here.
*/ | ||
protected function getNodeDepth(DomNode $node) | ||
{ | ||
$depth = -2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add some info about this parameter?
/** | ||
* @var \eZ\Publish\Core\FieldType\RichText\RendererInterface|\PHPUnit\Framework\MockObject\MockObject | ||
*/ | ||
protected $rendererMock; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We place class attributes at the begging of the class
$this->customStylesConfiguration = $customStylesConfiguration; | ||
} | ||
|
||
public function renderStyle($name, array $parameters, $isInline) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing docblock
*/ | ||
protected function getStyleTemplateName($identifier, $isInline) | ||
{ | ||
if (isset($this->customStylesConfiguration[$identifier]) && !empty($this->customStylesConfiguration[$identifier]['template'])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!empty($this->customStylesConfiguration[$identifier]['template'])
will be enough if $customStylesConfiguration
is initialize as array
{ | ||
return $ezRichTextNode | ||
->arrayNode('custom_styles') | ||
// workaround: take into account Custom Tag names when merging configs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: Custom Style
Note: it requires rebase, so while at it I'm gonna also address latest review comments to unblock our QA. |
cf7a3a9
to
3b0c151
Compare
Rebased |
Added a way to declare and use custom "styles" in richtext (https://alloyeditor.com/docs/features/styles.html)
3b0c151
to
a67c1fb
Compare
…part of my text (#2427) * EZP-29554: Added Custom Styles support for RichText Field Type Added a way to declare and use custom "styles" in richtext (https://alloyeditor.com/docs/features/styles.html) * EZP-29554: Added improvements after code review
…part of my text This commit is a squash of the following ezpublish-kernel commits: - ezsystems/ezpublish-kernel@36f372c (ezsystems/ezpublish-kernel#2427) - ezsystems/ezpublish-kernel@143d9a6 (ezsystems/ezpublish-kernel#2457) * EZP-29554: Added Custom Styles support for RichText Field Type Added a way to declare and use custom "styles" in richtext (https://alloyeditor.com/docs/features/styles.html) * EZP-29664: Stored Custom Styles as eztemplate and eztemplateinline
7.x
TODO:
$ composer fix-cs
).Added a way to declare and use custom "styles" in richtext (https://alloyeditor.com/docs/features/styles.html)
PR for the admin ui : ezsystems/ezplatform-admin-ui#602
Configure the custom style
Default templates
Block template :
Inline template :
Labels
Custom styles label are generated using SF translation.
Translation domain is "custom_styles".