CKEditor 5 templates are dumped inside of existing ones if not manually deleted

Created on 3 April 2024, 8 months ago
Updated 5 April 2024, 8 months ago

Problem/Motivation

When multiple templates have been created, and one has already been applied, it must be manually removed before adding the new template. If not, then the new template is dumped inside the existing template at whatever point the cursor happens to be at.

Proposed resolution

Perhaps it's only me that finds this to be a not so great experience, but if not, I propose that the CKEditor be cleaned out automatically before the new template is dropped in.

Remaining tasks

Check the patch.

User interface changes

The CKEditor content is dropped before the new template replaces it. (It would be a nice feature if you were changing variations of a template that pre-existing content would be ported into the new template).

PS: I've also removed what I assume is a rogue console.log statement.

✨ Feature request
Status

Closed: won't fix

Version

1.0

Component

User interface

Created by

πŸ‡¦πŸ‡ΊAustralia jaydee1818 Melbourne

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

Comments & Activities

  • Issue created by @jaydee1818
  • πŸ‡¦πŸ‡ΊAustralia jaydee1818 Melbourne
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.2.1 + Environment: PHP 8.1 & MySQL 8
    34:14
    43:56
    Running
  • Status changed to Closed: won't fix 8 months ago
  • πŸ‡©πŸ‡ͺGermany vincent.hoehn Dresden, Germany

    Hello Jonathan,

    Thank you very much for creating the issue and the effort for the patch.

    The patch deletes the complete content of the editor before inserting a new template.
    This is not a problem if the node is new and only one template is included, which is then β€œchanged”.
    However, this is disastrous if large and important content already exists. This is then removed.

    For example, we use Drupal to create our manuals for our software. We use the template module to easily add recurring content such as notes, images, warnings, etc. Some text is several pages long, applying the patch and inserting a template would destroy the content.

    BR
    Vincent

  • πŸ‡©πŸ‡ͺGermany dbielke1986

    I see it the same way. Completely removing the content is fatal for many use cases.

    Regarding the actual problem, please take a look at the linked items.

  • πŸ‡¦πŸ‡ΊAustralia jaydee1818 Melbourne

    Ok then - how about this idea. Add the option to override the current template? Set to false by default but change it to true if that behaviour suits your use-case?

    {
        "title": "Banner Variant One",
        "icon": "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path d=\"M8 16h8v2H8zm0-4h8v2H8zm6-10H6c-1.1 0-2 .9-2 2v16c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6zm4 18H6V4h7v5h5v11z\"/></svg>",
        "description": "2-col - LHS: Text, RHS: Image",
        "override": true,
        "html": "<div>My template</div>"
      },
    
  • πŸ‡©πŸ‡ͺGermany vincent.hoehn Dresden, Germany

    I don't think we can implement it that easily.
    With override=true, the source code would have to go through the content and find the template. But what if there are several identical templates in the document?

    Moreover, the entire logic would have to be rebuilt, as the additional key in the JSON would have to become a recursive function. I don't know if it's worth the effort, I think manual deletion is the more suitable option.

Production build 0.71.5 2024