Problem/Motivation

See #2994696-214: Render embedded media items in CKEditor, patch review point 2:

🤔 In #25, this used to be more abstract:

          // Allow entity_embed.editor.css to respond to changes (for example in alignment).
          this.element.setAttributes(this.data.attributes);

It was more abstract for a reason: custom and contrib modules may layer additional behavior, styling or semantics on top of existing HTML elements by adding more data- attributes. For example, data-highlight, data-editor-comments, data-invert-colors, data-mirror , data-geolocation, and so on. That's exactly what FilterAlign does via data-align and FilterCaption via data-caption. This

The current code hardcodes only behavior for data-align. Yes, I know this plugin has special behavior for data-caption. There's no other way for that one. But data-align was implemented generically, and at least some other data-somethings could achieve the same.

In my opinion, this is a regression compared to earlier patch iterations. But I won't block the patch over this.

In #216 of that issue, we brought that back, to not break that use case. But that means the align-* classes are no longer absolutely necessary, they're just the equivalent of syntactic sugar.

Proposed resolution

Remove the align-* classes, i.e. remove this code:

          if (this.data.attributes.hasOwnProperty('data-align')) {
            this.element
              .getParent()
              .addClass('align-' + this.data.attributes['data-align']);
          }

Remaining tasks

TBD

User interface changes

TBD

API changes

TBD

Data model changes

TBD

Release notes snippet

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Wim Leers created an issue. See original summary.

phenaproxima’s picture

Title: [PP-1] Consider no longer generating align-* classes for preview in DrupalMedia CKEditor plugin » Consider no longer generating align-* classes for preview in DrupalMedia CKEditor plugin
oknate’s picture

oknate’s picture

I tested this out this morning, and it's jarring to set it right-aligned and then see it display in the WYSIWYG as centered. While I think this would simplify the code and reduce maintenance on the drupalmedia plugin.js, I think the UX problem of not having some sort of alignment preview in the WYWIWYG is too great. So I'm voting against this until I can be convinced otherwise.

I'm updating this comment 9 days later: The ask here is not to stop aligning the media in the WYSIWYG, but to go back to using the data-align attribute.

oknate’s picture

I'm not sure I understand this:

 the align-* classes are no longer absolutely necessary, they're just the equivalent of syntactic sugar.

You mean, we could use the data-align for the css?

Wim Leers’s picture

Wim Leers’s picture

I tested this out this morning, and it's jarring to set it right-aligned and then see it display in the WYSIWYG as centered.

But that's because we chose to make the CSS selectors rely on classes instead of data- attributes. That's easily changed. If we change that, then everything continues to function exactly the same.

Wim Leers’s picture

lauriii’s picture

Thank you @Wim Leers for walking through this issue with me on a call. I think we should solve this rather than #3081357: Media alignment mismatch between the WYSIWYG and rendered media -- drupalmedia.js shouldn't convert data-align properties when Filter Align disabled. @Wim Leers explained that this is currently added to an element that is added by CKEditor only in CKEditor. This helped me understand that only CKEditor specific CSS should be able to change styling of this element. I'm sorry to cause us to go back and forth on this, but I do think this is a better approach. This allows us to close #3081357: Media alignment mismatch between the WYSIWYG and rendered media -- drupalmedia.js shouldn't convert data-align properties when Filter Align disabled and should also simplify some of the code in #3078287: Constrain the width of aligned images, media, blockquotes etc to a max of 75%.

oknate’s picture

Title: Consider no longer generating align-* classes for preview in DrupalMedia CKEditor plugin » [PP-1] Consider no longer generating align-* classes for preview in DrupalMedia CKEditor plugin
FileSize
6.77 KB
9.48 KB

Here's an initial patch for this. Unfortunately, I found a bug that wasn't an issue when we were adding our own classes, but now is getting in the way of this issue. #3084340: drupalmedia plugin.js doesn't delete attributes from drupal-media element when unset.

Other than that, this seems ready to me. Perhaps I'll test more, for example with Umami. But it works fine.

phenaproxima’s picture

Title: [PP-1] Consider no longer generating align-* classes for preview in DrupalMedia CKEditor plugin » Consider no longer generating align-* classes for preview in DrupalMedia CKEditor plugin

Not postponed anymore!

oknate’s picture

Actually, I postponed it five minutes ago, because I think #3084340: drupalmedia plugin.js doesn't delete attributes from drupal-media element when unset. is a blocker.

phenaproxima’s picture

Title: Consider no longer generating align-* classes for preview in DrupalMedia CKEditor plugin » [PP-1] Consider no longer generating align-* classes for preview in DrupalMedia CKEditor plugin
Status: Active » Postponed

Whoops, sorry! Let's get that one fixed.

oknate’s picture

One coding standard warning:

10251/source/core/modules/media/tests/src/FunctionalJavascript/CKEditorIntegrationTest.php ✗ 1 more
1076	Whitespace found at end of line
oknate’s picture

Title: [PP-1] Consider no longer generating align-* classes for preview in DrupalMedia CKEditor plugin » [PP-1] Stop generating align-* classes for preview in DrupalMedia CKEditor plugin

Dropping "Consider" from issue title.

larowlan’s picture

Title: [PP-1] Stop generating align-* classes for preview in DrupalMedia CKEditor plugin » Stop generating align-* classes for preview in DrupalMedia CKEditor plugin
Status: Postponed » Active

Blocker is in

oknate’s picture

Assigned: Unassigned » oknate
Status: Active » Needs review
FileSize
6.74 KB

Thanks, @larowlan! Here's a reroll of #10.

Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community

Manually tested.

Works perfectly.

Wim Leers’s picture

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Awesome, this ends up being a nice simplification of the code, in addition to fixing up things!

Committed and pushed to 8.8.x. Thanks!

  • webchick committed 23f61fd on 8.8.x
    Issue #3072279 by oknate, Wim Leers: Stop generating align-* classes for...
Wim Leers’s picture

Status: Fixed » Closed (fixed)

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