Templates with the same title collide

Created on 29 September 2023, about 1 year ago
Updated 16 October 2023, about 1 year ago

Problem/Motivation

I had two templates in the ckeditor_templates (CKE4) module that have the same "title". In the CKE4 module, both the templates showed up correctly...even though we should not name them the same...we will update the template config, but it did lead to me finding this bug.

However, in this module's CKE5 version, the title key seems to be unique and I got the same template repeated instead of two different templates. So, I went to update the title in the JSON file mentioned in the "/admin/config/content/formats/manage/ckeditor_5" config section, and after that, the two templates were discrete.

Interestingly, when the titles were the same, the different descriptions did show up in the tooltip. And looking at the code, it seems like templates stay distinct there too.

Steps to reproduce

1. Install the module and create a template JSON file with the same template repeated twice. Exact same title, description, and HTML.
2. Before saving any CKE5 config options, update the second template to have a different description and HTML.
3. Add the CKE5 text format to a text field and load the CKE5 toolbar.
4. See the template title repeated for the two template options, but notice that the description is different.
5. Add the two templates and notice the output is identical.
6. Update your JSON template file to make the titles unique, save the config, and clear Drupal's cache.
7. Load the CKE5 editor again, and see two distinct titles.
8. Add the two templates and notice the output is different.

Proposed resolution

I thought maybe there is a place where the code looks for something based on the title key vs. the index of the template object in an array.

I think it is on line #56 in template.js

const template = templateArray.find(template => template.title === event.source.label);

I can totally understand your answer being "don't label the templates exactly the same", but just as FYI, this seems like it was legal in the ckeditor_templates module for anyone trying to migrate from that codebase.

Maybe adjusting a readme or docs for upgrading from the other module would be good enough to deal with this issue?

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States afinnarn

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024