Problem/Motivation

CKEditor does not allow you to specify multiple styles with the same label (see #4). But Drupal core's CKEditor integration does not prevent this: it does not do the necessary validation.

Therefore when users enter multiple identical labels, they can end up with a CKEditor instance whose StylesCombo plugin doesn't work correctly, because it is being fed invalid configuration.

Proposed resolution

Add validation.

Remaining tasks

  1. Write validation code.
  2. Add test coverage, at \Drupal\ckeditor\Tests\CKEditorStylesComboAdminTest.

User interface changes

No changes, except that invalid StylesCombo configuration will now trigger a validation error.

API changes

None.

Data model changes

None.

Comments

maskedjellybean created an issue. See original summary.

maskedjellybean’s picture

Issue summary: View changes
maskedjellybean’s picture

Issue summary: View changes
wim leers’s picture

Title: Duplicate labels for Styles dropdown causes Styles to not render » Duplicate labels for Styles dropdown causes Styles to not render: add validation to prevent this
Status: Active » Needs review
Issue tags: -styles combo, -styles dropdown, -labels +Needs tests, +Novice, +php-novice
StatusFileSize
new1.27 KB

CKEditor explicitly doesn't allow that:

A unique name must be assigned to your style definition […]

Source: http://docs.cksource.com/CKEditor_3.x/Developers_Guide/Styles


So, that means our validation is insufficient. Nice catch!

Here's a patch that adds the necessary validation. Now the only thing that's still necessary, is test coverage.

Orizontal’s picture

Issue tags: +DrupalNorth2016

Testing this issu

Orizontal’s picture

bohemier’s picture

Testing with Orizontal @DrupalNorth

Orizontal’s picture

Orizontal’s picture

We applied the patch: cke_styles_unique_name_validation-2749475-4.patch and we reproduce the issue. We did received a validation error: Each style must have a unique label. We did change the style label to use unique label. Now we can apply the style to the list. The validation is working. We did verify that the html style are working when inspecting the generated html. Nothing much to do with core gates.

penyaskito’s picture

Status: Needs review » Needs work

Thanks for testing it, @Orizontal and @bohemier!

Looks like the behavior is as expected, next action would be adding an automated test for ensuring it.

penyaskito’s picture

Priority: Minor » Normal

I think this is a Normal bug according to https://www.drupal.org/node/45111, not a Minor.

wim leers’s picture

Thanks for testing & confirming!

wim leers’s picture

Issue summary: View changes
Issue tags: +drupaldevdays

This would be a great issue for a new contributor to work on at DrupalDevDays Milan!

Updated the issue summary for clarity.

So what still needs to be done is adding test coverage, at \Drupal\ckeditor\Tests\CKEditorStylesComboAdminTest. You can look at \Drupal\ckeditor\Tests\CKEditorAdminTest for examples — you should be able to reuse significant parts :)

(It needs to be a separate test because this is not testing the overall CKEditor configuration UI, but only one particular plugin's settings form. This then sets the right example for contrib modules.)

wim leers’s picture

Issue summary: View changes
thpoul’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new6.37 KB
new7.52 KB

Since drupaldevdays is over and this is a bug report for 8.1.x, I thought this should get moved forward. Here are the test-only and the full patch. Hopefully it's on the right track based on #13

The last submitted patch, 15: 2749475-15-test-only.patch, failed testing.

wim leers’s picture

Issue tags: -drupaldevdays

Agreed! Thanks :)

wim leers’s picture

Status: Needs review » Needs work
Issue tags: -Novice, -php-novice
  1. +++ b/core/modules/ckeditor/src/Tests/CKEditorStylesComboAdminTest.php
    @@ -0,0 +1,151 @@
    +      'format' => 'filtered_html',
    ...
    +      'format' => 'filtered_html',
    

    Let's use $this->randomMachineName().

  2. +++ b/core/modules/ckeditor/src/Tests/CKEditorStylesComboAdminTest.php
    @@ -0,0 +1,151 @@
    +      'name' => 'Filtered HTML',
    

    $this->randomString()

  3. +++ b/core/modules/ckeditor/src/Tests/CKEditorStylesComboAdminTest.php
    @@ -0,0 +1,151 @@
    +  /**
    +   * Tests StylesCombo settings for an existing text format.
    +   */
    +  function testExistingFormat() {
    ...
    +  /**
    +   * Tests StylesCombo settings for a new text format.
    +   */
    +  function testNewFormat() {
    

    Do we really need both of these? I think just one will do.

  4. +++ b/core/modules/ckeditor/src/Tests/CKEditorStylesComboAdminTest.php
    @@ -0,0 +1,151 @@
    +    // Ensure an Editor object exists, with the proper settings.
    

    s/object/config entity/

thpoul’s picture

Status: Needs work » Needs review
StatusFileSize
new6.46 KB
new4.76 KB

Thank you for the review Wim, here is the updated patch.

Do we really need both of these? I think just one will do.

+1

wim leers’s picture

Status: Needs review » Reviewed & tested by the community

Thanks! Found another few nits, but those don't need to block commit.

  1. +++ b/core/modules/ckeditor/src/Tests/CKEditorStylesComboAdminTest.php
    @@ -0,0 +1,99 @@
    +  protected function setUp() {
    

    Missing {@inheritdoc}.

  2. +++ b/core/modules/ckeditor/src/Tests/CKEditorStylesComboAdminTest.php
    @@ -0,0 +1,99 @@
    +    // Create text format.
    ...
    +      'weight' => 0,
    ...
    +    // Create admin user.
    

    These can be removed IMO.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 19: 2749475-19.patch, failed testing.

thpoul’s picture

Status: Needs work » Reviewed & tested by the community

Unrelated test failure back to RTBC

thpoul’s picture

StatusFileSize
new994 bytes
new4.72 KB

And here are the nits trying to make the life easier to our beloved committers!

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 23: 2749475-23.patch, failed testing.

wim leers’s picture

Status: Needs work » Reviewed & tested by the community

Random fails in upgrade path tests. Retesting. Back to RTBC.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed f2d19d2d2bee3229fd0730af4fb95ace4d5de3ad to 8.2.x and a6b370b to 8.1.x. Thanks!

  • alexpott committed f2d19d2 on 8.2.x
    Issue #2749475 by thpoul, Wim Leers, maskedjellybean, Orizontal,...

  • alexpott committed a6b370b on 8.1.x
    Issue #2749475 by thpoul, Wim Leers, maskedjellybean, Orizontal,...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.