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-29554: As an editor, I want to be able to apply custom styles to part of my text #2427

Merged
merged 2 commits into from Sep 13, 2018

Conversation

erdnaxelaweb
Copy link
Contributor

@erdnaxelaweb erdnaxelaweb commented Aug 21, 2018

Question Answer
JIRA issue https://jira.ez.no/browse/EZP-29554
Bug/Improvement yes
New feature yes
Target version 7.x
BC breaks no
Tests pass no
Doc needed yes

TODO:

  • Implement feature / fix a bug.
  • Implement tests.
  • Fix new code according to Coding Standards ($ composer fix-cs).
  • Ask for Code Review.

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

ezpublish:
    system:
        default:
            fieldtypes:
                ezrichtext:
                    custom_styles: [highlighted_block, highlighted_word]
    
    ezrichtext:
        custom_styles:
            highlighted_word:
                template: '@ezdesign/field_type/ezrichtext/custom_style/highlighted_word.html.twig'
                inline: true
            highlighted_block:
                template: '@ezdesign/field_type/ezrichtext/custom_style/highlighted_block.html.twig'
                inline: false

Default templates

Block template :

<div class="{% if align is defined %}align-{{ align }}{% endif %} style-{{ name }}">{% spaceless %}{{ content|raw }}{% endspaceless %}</div>

Inline template :

<span class="style-{{ name }}">{% spaceless %}{{ content|raw }}{% endspaceless %}</span>

Labels

Custom styles label are generated using SF translation.
Translation domain is "custom_styles".

ezrichtext.custom_styles.highlighted_block.label: Highlighted block
ezrichtext.custom_styles.highlighted_word.label: Highlighted word

}

if (!$this->templateEngine->exists($templateName)) {
if (isset($this->logger)) {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

@alongosz alongosz changed the title As an editor, i want to be able to apply custom styles to part of my text EZP-29554: As an editor, I want to be able to apply custom styles to part of my text Aug 31, 2018
Copy link
Member

@alongosz alongosz left a 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:

  1. 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.

  2. 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>
Copy link
Member

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>
Copy link
Member

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)) {
Copy link
Member

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 -->
Copy link
Member

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]">
Copy link
Member

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.

@ezrobot

This comment has been minimized.

@erdnaxelaweb
Copy link
Contributor Author

Fixed requested change from @alongosz and failed tests

@micszo micszo self-assigned this Sep 11, 2018
Copy link
Contributor

@ViniTou ViniTou left a 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;
Copy link
Contributor

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;
Copy link
Contributor

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)
Copy link
Contributor

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'])) {
Copy link
Contributor

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: Custom Style

@alongosz
Copy link
Member

Note: it requires rebase, so while at it I'm gonna also address latest review comments to unblock our QA.

@alongosz
Copy link
Member

alongosz commented Sep 11, 2018

Rebased
@mikadamczyk I resolved your (and my) requests via 3b0c151

@micszo micszo removed their assignment Sep 13, 2018
@alongosz alongosz merged commit 36f372c into ezsystems:master Sep 13, 2018
andrerom pushed a commit that referenced this pull request Oct 4, 2018
…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
alongosz pushed a commit to alongosz/ezplatform-richtext that referenced this pull request Oct 15, 2018
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
8 participants