Problem/Motivation

DrupalMedia plugin's plugin.js has this code:

this.element.setAttributes(this.data.attributes);

This unfortunately doesn't unset attributes such as 'data-align' as one would expect. If in the dialog, you set 'data-align' to 'none', one expects that it's removed from the embed. While it does remove it from the downcast embed, it doesn't remove it from the drupal-media element inside the widget. It doesn't unset previously set attributes.

This is a blocker for #3072279: Stop generating align-* classes for preview in DrupalMedia CKEditor plugin

this.element is a CKEDITOR.dom.element:

window.CKEDITOR.window.CKEDITOR.dom.CKEDITOR.dom.element {$: drupal-media.cke_widget_element}
$: drupal-media.cke_widget_element
...
attributes: NamedNodeMap
0: data-cke-widget-data
1: data-cke-widget-upcasted
2: data-cke-widget-keep-attr
3: data-widget
4: class
5: data-view-mode
6: data-caption
7: data-entity-type
8: data-entity-uuid
9: data-align
...

Proposed resolution

I think we need to iterate through the old data attributes and remove them (this.oldData.attributes in drupalmedia plugin.js)

If you try this.element.removeAttributes() and then set the attributes, CKEditor blows up, because some of the attributes are internal to CKEditor.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

oknate created an issue. See original summary.

oknate’s picture

Status: Active » Needs review
FileSize
1.21 KB
4.87 KB

Here's a patch to fix it.

oknate’s picture

Issue summary: View changes

The last submitted patch, 2: 3084340-2--FAIL.patch, failed testing. View results

Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Media Initiative
larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Committed b1f525d and pushed to 8.8.x. Thanks!

  • larowlan committed b1f525d on 8.8.x
    Issue #3084340 by oknate: drupalmedia plugin.js doesn't delete...
oknate’s picture

Thanks!

Wim Leers’s picture

Status: Fixed » Closed (fixed)

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