Problem/Motivation

Using Editor Advanced Link to expose the CSS Class field on the Link Dialog in text editors I figured out that a strange "cke_widget_element" class was appended in the field.

Steps to reproduce

  1. install Drupal and Editor advanced link
  2. log in as user#1
  3. add a node
  4. insert an image in the content
  5. put a link on the image
  6. edit the link (right click)
  7. open the "advanced" fieldset

Expected result: the CSS class field is empty
Current result: the CSS class field contains "cke_widget_element"

Proposed resolution

Figure out where it comes from and clean it.

Remaining tasks

Seek, Destroy

User interface changes

No more "cke_widget_element" class in the css class field

API changes

None.

Data model changes

None.

Comments

DuaelFr created an issue. See original summary.

wim leers’s picture

Quoting plugins/widget/plugin.js in CKEditor:

		destroy: function( offline ) {
			…

			if ( !offline ) {
				if ( this.element.data( 'cke-widget-keep-attr' ) == '0' )
					this.element.removeAttribute( 'data-widget' );
				this.element.removeAttributes( [ 'data-cke-widget-data', 'data-cke-widget-keep-attr' ] );
				this.element.removeClass( 'cke_widget_element' );
				this.element.replace( this.wrapper );
			}

			…
		}, 

It is those attributes that are being picked up by drupallink's link parsing. This will be true for any widget that can be wrapped in a link.

The reason that CKEditor's image2 + link don't suffer from this, is because link is hardcoded to a limited set of attributes that it supports (i.e. also not class). Compare to Drupal 8's drupallink plugin, which supports any attribute (i.e. also class).

Needs feedback from the CKEditor team on how to best solve this, because AFAICT the Widget API does not have an API to determine which attributes and attribute values should be ignored. I suspect the answer will be: any class with the cke_widget_* prefix and any attribute with the data-cke-widgetprefix.

mlewand’s picture

We're also preventing this class to leak into our link's advanced tab (it can be enabled using config). And just as you've assumed we're simply dropping cke_* classes and it's working just fine, see https://github.com/ckeditor/ckeditor-dev/blob/cce5ef6e8583e25392e3910b80...

wim leers’s picture

Assigned: Unassigned » wim leers
Issue tags: +JavaScript

Alright, thanks!

Working on a patch.

wim leers’s picture

Assigned: wim leers » Unassigned
Status: Active » Needs review
Issue tags: +Needs manual testing
StatusFileSize
new1.54 KB
duaelfr’s picture

Issue tags: -Needs manual testing
StatusFileSize
new1.29 KB
new1.07 KB

As told on IRC I suggest to wipe all data-cke-* attributes as advices by the CKEditor team.
I also suggest to use indexOf instead of substring for clarity.

I did the manual testing with editor_advanced_link and both patches fix the issue.

thpoul’s picture

Status: Needs review » Postponed (maintainer needs more info)

I don't seem able to replicate the issue on fresh 8.0.x with editor_advanced_link 8.x.1.0, so I haven't been able to manual test #5

Tried with Full HTML editor. Added a link and played around with it. Saved, edited and added class then saved, edited again removed class and added title, etc.

@DuaelFr could you please provide the steps to reproduce?

duaelfr’s picture

Status: Postponed (maintainer needs more info) » Needs review

Sure!
The thing happens when you edit a link that was added on an image.

duaelfr’s picture

Issue summary: View changes

Added steps to reproduce

duaelfr’s picture

Issue summary: View changes
wim leers’s picture

#8 I can't reproduce it when editing a linked image.

  1. The link before editing:
    <a class="foo bar" href="http://image1" id="test"><img alt="Guust" data-align="center" data-caption="hoi, dit is een &lt;a href=&quot;http://caption2&quot;&gt;test&lt;/a&gt;" data-entity-type="file" data-entity-uuid="42960199-c264-468a-aa54-8423777396e3" src="/sites/default/files/inline-images/search.jpg" /></a>
    
  2. After editing the link (note the new har class):
    <a class="foo bar har" href="http://image1" id="test"><img alt="Guust" data-align="center" data-caption="hoi, dit is een &lt;a href=&quot;http://caption2&quot;&gt;test&lt;/a&gt;" data-entity-type="file" data-entity-uuid="42960199-c264-468a-aa54-8423777396e3" src="/sites/default/files/inline-images/search.jpg" /></a>
    
    
wim leers’s picture

Oh, it's in the dialog itself. That I also cannot reproduce… weird!

duaelfr’s picture

Beware of Chrome's cache ;)

thpoul’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new186.71 KB
new192.13 KB

Thank you @DuaelFr

I can confirm that manual testing #6 works.

Attaching screenshots for the record.

wim leers’s picture

Status: Reviewed & tested by the community » Needs work

NW for a nit:

+++ b/core/modules/ckeditor/js/plugins/drupallink/plugin.js
@@ -18,13 +18,8 @@
+      // Ignore data-cke-* attributes; they're CKEditor Widget internals.

This comment is now incorrect. It's not "CKEditor Widget internals" but just "CKEditor internals" now.

thpoul’s picture

Status: Needs work » Needs review
StatusFileSize
new718 bytes
new1.29 KB

Here you go.

wim leers’s picture

Status: Needs review » Reviewed & tested by the community
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.1.x and cherry-picked to 8.0.x. Thanks!

  • catch committed 03d49cf on 8.1.x
    Issue #2669898 by thpoul, DuaelFr, Wim Leers: cke_widget_element CSS...

  • catch committed b8263f0 on 8.0.x
    Issue #2669898 by thpoul, DuaelFr, Wim Leers: cke_widget_element CSS...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.