Review main Merged

84679[BUGFIX] Allow to use CKEditor style definitions with an empty class

Garvin Hicking CR +2 V +2 Easy +29 −8 updated 08/29/24, 09:58

Commit message

The CKEditor default YAML configuration for the Full and Default
presets contained code like:

```
- { name: 'Orange title H2', element: 'h2', classes: [],
    styles: { color: 'orange', background: 'blue' } }
- { name: 'Orange title H3', element: 'h3', classes: [],
    styles: { color: 'orange', background: 'blue' } }
- { name: 'Quote / Citation', element: 'blockquote', classes: [],  }
- { name: 'Code block', element: 'code', classes: [],  }
- { name: 'Yellow marker', element: 'span', classes: [],
    styles: { background-color: 'yellow' } }
```

and

```
- { name: "Lead", element: "p", classes: ['lead'] }
- { name: "Small", element: "small", classes: [] }
- { name: "Muted", element: "span", classes: ['text-muted'] }
```

CKEditor 5 expects the "classes" attribute to contain an array of
strings (or just a string) and not an empty array. Otherwise
choosing such a style  will have no effect in the CKEditor instance.

The CKEditor5Migrator class has been enhanced to convert these
empty or absent arrays to a `['']` definition on the fly. This allows
integrators to continue using their hard-earned CKEditor
YAML configurations without further change.

The default YAML presets have been changed to omit the classes
attribute, as that's what the intention of the configuration is.
While this is a proprietary TYPO3 modification, we need this
because of limited CKEditor5 functionality regarding classes handling.
Also, the no longer valid "styles:" definitions have been removed.

Review

  • Code review CR +2 Done
    • Garvin Hicking +2
    • Benjamin Franzke +1
    • Benni Mack +1
  • Verified V +2 Done
    • Garvin Hicking +2
    • Benjamin Franzke +1
    • Benni Mack +1
    • core-ci +1 CI

Issues 2

Files 4

Review log 2231

Show 46 earlier messages
  1. Garvin Hicking uploaded patch set 1 06/13/24, 08:21

  2. Garvin Hicking commented on patch set 1 06/13/24, 08:22

  3. core-ci voted on patch set 1 V -1 06/13/24, 08:28 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/59423

  4. Garvin Hicking uploaded patch set 2 V -1 06/13/24, 10:05

    cgl
  5. core-ci voted on patch set 2 V +1 06/13/24, 10:18 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/59455

  6. Harald Witt voted on patch set 2 CR +1 06/13/24, 11:10

  1. Harald Witt voted on patch set 2 V +1 06/13/24, 11:11

  2. Mogens Fiebrandt voted on patch set 2 CR +1 V +1 06/29/24, 11:07

  3. Stefan Bürk commented on patch set 2 CR -1 06/29/24, 13:29

    CKEditor5Migrator.php:963

    Would it work when unsetting the classes key if it is an empty array ? ``` if ($definition['classes'] === []) { unset($definition['classes']); } ``` Providing a empty string as "class" looks wrong in all ways. Can you check if unsetting would be a (nicer) working fix here instead ?
  4. Garvin Hicking commented on patch set 2 06/29/24, 16:44

    CKEditor5Migrator.php:963 Reply

    If I unset the 'classes' key, there are several places in the code that currently expect 'classes' to always be an array (line 1001, 627, 630, 729, 993). I'm thinking fixing it everywhere there to deal with the array key not existing would introduce further regression issues. Fixing this with an empty string array key seems to be the safer bet here, IMO.
  5. Garvin Hicking uploaded patch set 3 CR +1 V +1 07/16/24, 15:38

    rework
  6. core-ci voted on patch set 3 V +1 07/16/24, 15:45 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/61646

  7. Garvin Hicking commented on patch set 3 07/16/24, 15:50

    CKEditor5Migrator.php:963 Reply

    OK, with https://forge.typo3.org/issues/103499 I did some more digging: https://ckeditor.com/docs/ckeditor5/latest/api/module_style_styleconfig-StyleDefinition.html this defines "classes" to be an array. It cannot be missing (then the CKEditor style dropdown no longer works). So we cannot unset it, even if we address all the references to the attribute in the CKMigrator Code. Also, setting this attribute to "true" or "false" or "null" (without quotes) just leads to CKEditor using `<code class="true">`, `<code class="false">` and `<code class="null">` there. Also, using `['']` actually leads to `<code class="">` getting inserted. But I do not see a way around this with current CKEditor5, this would need reporting as a CKEditor5 bug presumably. I've asked this as a question (https://github.com/ckeditor/ckeditor5/issues/16737) for now, but guess we will need an interrim solution like outlined here.
  8. Garvin Hicking rebased onto patch set 4 V +1 07/31/24, 08:08

  9. core-ci voted on patch set 4 V +1 07/31/24, 08:15 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/62502

  10. Garvin Hicking commented on patch set 4 08/02/24, 13:18

    CKEditor5Migrator.php:963 Reply

    (Marking this as resolved because I'm fairly certain there'll be no movement from CKEditor5 on this as an alternative)
  11. Garvin Hicking rebased onto patch set 5 V +1 08/02/24, 13:18

  12. core-ci voted on patch set 5 V +1 08/02/24, 13:25 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/62731

  13. Simon Schaufelberger uploaded patch set 6 V +1 08/22/24, 23:05

  14. core-ci voted on patch set 6 V -1 08/22/24, 23:10 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/64026

  15. Simon Schaufelberger rebased onto patch set 7 V -1 08/22/24, 23:12

  16. core-ci voted on patch set 7 V +1 08/22/24, 23:17 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/64027

  17. Garvin Hicking uploaded patch set 8 V +1 08/29/24, 07:32

  18. core-ci voted on patch set 8 V +1 08/29/24, 07:49 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/64460

  19. Benjamin Franzke uploaded patch set 9 V +1 08/29/24, 08:25

  20. Benjamin Franzke commented on patch set 9 08/29/24, 08:25

    I've been long very reserved about this change, but I tried to fix CKEditor5 directly (their contribution CLA process sucks and it isn't to change additionally). …but I figured – if we introduce/keep-on with custom syntax here – we should strive for the configuration format that we desire, that is: Do not specifiy empty classes array at all, but omit it. Although we're not happy with the rendering yet, this patch fixes the missing element-application, therefore I'm fine with this now. @gh@faktor-e.de I hope my change is fine with you.
  21. Garvin Hicking commented on patch set 9 08/29/24, 08:33

    Reply

    I love that alteration, I wish I came up with it. This makes the YAML lean and understandable, but "fixes" the old syntax, great.
  22. core-ci voted on patch set 9 V +1 08/29/24, 08:41 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/64461

  23. Benni Mack voted on patch set 9 CR +1 V +1 08/29/24, 09:23

  24. Garvin Hicking commented on patch set 9 CR +2 V +2 08/29/24, 09:57

    preparing backport
  25. Garvin Hicking merged patch set 10 08/29/24, 09:58