After saving a node the CKEditor model of an element changes

Created on 5 January 2023, almost 2 years ago
Updated 14 April 2023, over 1 year ago

Problem/Motivation

I created a custom plugin that makes use of the a tag which when used, styles the link as a button. I was able to successfully achieve this and verified that the model name is "button" as I added in the code, using the CKEditor inspector. Moving back and forth between the ckeditor view and the source view keeps the model name intact. However upon saving the node and going back to the edit screen the model name of the selection changes to "linkHref" which after some investigation appears to be used by the link plugin in CKEditor. I can't tell if this is a Drupal issue or a ckeditor 5 issue. I set the priority level on the conversion downcast to 5 and the priority level on the conversion upcast to 'high' but that didn't help in maintaining the expected model which would activate a different balloon.

Steps to reproduce

Create a plugin using the a tag as an attribute on the generic $text element
Save node

💬 Support request
Status

Closed: works as designed

Version

9.5

Component
CKEditor 5 

Last updated 3 days ago

Created by

🇺🇸United States bajah1701

Live updates comments and jobs are added and updated live.
  • JavaScript

    Affects the content, performance, or handling of Javascript.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    Great, but … that's a lot of code 😅 I don't think anybody will find themselves with enough free time to carefully read & study all that. You have a better chance of getting help if you first distill it down to the essence to reproduce this 😊

  • 🇺🇸United States bajah1701

    Well my hands are tied here. How to reproduce it would eventually require writing lots of boilerplate code anyway. I really don't know how else I can explain the problem other than what I have already written.

  • Hi @bajah1701!

    If I understand properly, you would like to have the possibility to insert an `` element, that will have additional classes, i.e. `btn` and `btn-primary`. I believe, the easiest way to achieve that, would be using existing link API, so you don't have to create a custom conversion.

    The link plugin introduces the concept of decorators that allows the integrator to define which additional attributes the link element should have. The decorator could be automatic (added automatically to the element) or manual (toggled with UI). Learn more about automatic decorators here and manual decorators here.

    The example configuration might look as below:

    		link: {
    			decorators: {
    				isButton: {
    					mode: 'manual',
    					label: 'Is button',
    					classes: [ 'btn', 'btn-primary' ]
    				}
    			}
    		}
    

    Which will result in additional button in the link form:

    and in the DOM:

    If you want to keep the separate button for your plugin, you can still take advantage of Link API, get the input from your UI and simply run the Link command and pass the decorator name as an argument
    editor.execute( 'link', 'https://ckeditor.com', { linkIsButton: true } )

    Note that the decorator attribute name starts with the `link` prefix, so the pattern is `link` + name from your configuration (starting from uppercase).

    Let me know if it helps!

  • 🇺🇸United States bajah1701

    @mgsy Thank you, thank you, thank you. I was not aware that this was possible. Greatly appreciated.

  • Status changed to Closed: works as designed over 1 year ago
Production build 0.71.5 2024