Problem/Motivation

I am working on a site which makes heavy use of the styles dropdown as part of the content authoring experience. Once config is exported, storing all of these styles in a string causes unreadable diffs and frequent merge conflicts.

My config looks something like:

    stylescombo:
      styles: "h2.section-title--large|Section title\r\nh2.page-title--tick|Success title\r\n... # And so on for quite some time..."

Proposed resolution

Create a schema for storing these settings which breaks out the stylecombo into a sequence. Proposed schema would look something like:

ckeditor.plugin.stylescombo:
  type: mapping
  label: 'Styles dropdown'
  mapping:
    styles:
      type: sequence
      label: 'List of styles'
      sequence:
        type: mapping
        mapping:
          style:
            type: string
            label: 'Style'
          label:
            type: label
            label: 'Label'
 

Which would transform the above into something like:

    stylescombo:
      styles:
        -
          style: 'h2.section-title--large'
          label: 'Section title'
        -
          style: 'h2.page-title--tick'
          label: 'Success title'

This also makes these labels translatable, although I admit that came to me as an afterthought while writing the schema.

Remaining tasks

Validate this is worth working on.

Write a patch.

User interface changes

None.

API changes

None.

Data model changes

Config schema changes.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Sam152 created an issue. See original summary.

Wim Leers’s picture

This totally makes sense! I see no reason not to do this, it's better on all fronts. The current code is pre-D8 thinking.

Thanks for filing this :) Any chance you can work on a patch? I'll provide reviews!

Sam152’s picture

Happy to work on a patch, my biggest concern is it somehow being a BC break. Not sure if config schema is directly an API.

Wim Leers’s picture

This configuration is likely only ever updated through the UI. The UI will remain the same. We've changed the structure of configuration in the past. What matters most is an update path, which is totally feasible.

So: I'm not concerned :)

I checked https://www.drupal.org/core/d8-bc-policy, and it doesn't mention configuration or configuration schema at all. Besides, we've done this sort of thing in the past. And much more complex ones. For example: #2308745: Remove rest.settings.yml, use rest_resource config entities. So I'm 99% certain this will be fine.

Sam152’s picture

Cool, thanks for validating this idea and approach.

Wim Leers’s picture

One suggestion. Instead of:

mapping:
          style:
            type: string
            label: 'Style'
          label:
            type: label
            label: 'Label'

using this would be clearer I think:

mapping:
          selector:
            type: string
            label: 'Style selector'
          label:
            type: label
            label: 'Style label'
Sam152’s picture

Status: Active » Needs review
FileSize
10.07 KB

Initial pass over this. There was already a structured representation of the data that was prepared and sent to the client for ckeditor. Using the same schema means if we configured or used the ckeditor feature in a different way in the future, the schema would support it already.

Status: Needs review » Needs work

The last submitted patch, 7: 2871351-stylescombo-schema-7.patch, failed testing.

Sam152’s picture

Status: Needs work » Needs review
FileSize
15.1 KB
6.5 KB

Test fixes.

Sam152’s picture

Few more tidy ups.

Wim Leers’s picture

Status: Needs review » Needs work
Issue tags: -Needs update path, -Needs update path tests

Great work here!

  1. +++ b/core/modules/ckeditor/ckeditor.install
    @@ -0,0 +1,27 @@
    +    if ($styles !== NULL && $editor->get('editor') === 'ckeditor') {
    

    I think it'd be more logical to break out of this loop early when the editor is not ckeditor?

  2. +++ b/core/modules/ckeditor/ckeditor.install
    @@ -0,0 +1,27 @@
    +      $generate_method = new ReflectionMethod(StylesCombo::class, 'generateStylesSetSetting');
    +      $generate_method->setAccessible(TRUE);
    

    Nice :)

  3. +++ b/core/modules/ckeditor/config/schema/ckeditor.schema.yml
    @@ -48,5 +48,21 @@ ckeditor.plugin.stylescombo:
    +          name:
    ...
    +          element:
    ...
    +          attributes:
    
    +++ b/core/modules/ckeditor/tests/src/Functional/CKEditorStylesComboAdminTest.php
    @@ -91,7 +107,18 @@ public function testExistingFormat() {
    +        'name' => 'Title',
    +        'element' => 'h1',
    +        'attributes' => ['class' => 'title']
    ...
    +        'name' => 'Callout',
    +        'element' => 'p',
    +        'attributes' => ['class' => 'callout']
    

    This matches the terminology in http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-stylesSet — so +1! :)

  4. +++ b/core/modules/ckeditor/src/Plugin/CKEditorPlugin/StylesCombo.php
    @@ -36,14 +37,10 @@ public function getFile() {
    -    $config = [];
    ...
    -    if (!isset($settings['plugins']['stylescombo']['styles'])) {
    -      return $config;
    -    }
    ...
    +    return [
    +      'stylesSet' => isset($settings['plugins']['stylescombo']['styles']) ? $settings['plugins']['stylescombo']['styles'] : [],
    +    ];
    

    This is a behavior change that we can avoid.

    i.e. if there was no stylescombo setting, then we would return the empty array. With these changes, that's no longer the case.

    Let's bring back the old behavior, to minimize change.

  5. +++ b/core/modules/ckeditor/src/Plugin/CKEditorPlugin/StylesCombo.php
    @@ -163,4 +178,28 @@ protected function generateStylesSetSetting($styles) {
    +  protected function generateStyleSetString($style_set) {
    

    Let's make this method static, because it does not depend on any object property.

  6. +++ b/core/modules/ckeditor/src/Tests/Update/StylesComboSchemaUpdateTest.php
    @@ -0,0 +1,67 @@
    +  public function testSchemaUpdate() {
    +    $this->runUpdates();
    +
    +    $this->assertStylesComboSettings('test_editor', [
    

    This is asserting the structure after the update — great! But it'd be good to also assert the structure before the update. i.e. to assert that it's a string.

Sam152’s picture

Status: Needs work » Needs review
FileSize
4.65 KB
15.52 KB

Thanks for the review!

1. Makes sense.
4. Good catch.
5. I almost never use this pattern, but makes total sense.
6. Added.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Project: Drupal core » CKEditor 4 - WYSIWYG HTML editor
Version: 9.5.x-dev » 1.0.x-dev
Component: ckeditor.module » Code

CKEditor has been removed from core, CKEditor 4 is removed from Drupal Core in 10.0.0