Problem/Motivation

Media Library: Default value for data-align attribute should not be center. Why? From #12:

We most often translate "left" into float: left;, "right" into float: right; and "center" into margin: auto. With "none", we take the item as-is, and have it flow normally based on its size and the text alignment of the container. So, at least for us, "center" is a conscious decision on how the item should be displayed, thus it shouldn't be the default.

Also, why would there be a "None" setting, if we consoder "center" as the "default" (i.e. unchanged) state?

Steps to reproduce

Embed a media item -- any media item -- into a WYSIWYG text area, leaving the default settings in place.

Proposed resolution

As per comment #4 and #5, the default value should be left to none.

Remaining tasks

  • Write a patch
  • Review the patch
  • Create tests

User interface changes

When embedding media items in WYSIWYG, they will have no alignment by default.

API changes

None.

Data model changes

None.

Release notes snippet

TBD

Comments

mel-miller created an issue. See original summary.

mel-miller’s picture

StatusFileSize
new1.41 KB

Patch to change default data-align attribute.

mel-miller’s picture

Assigned: Unassigned » mel-miller
Status: Active » Needs review
heikki.lahtela’s picture

Completely agree with this one, the default value should be left to none. Even better if we could declare it from field settings.

idebr’s picture

Assigned: mel-miller » Unassigned

The center alignment was suggested as a sensible default in #2994699: Create a CKEditor plugin to select and embed a media item from the Media Library #15

peterhebert’s picture

Center alignment is not a sensible default - IMO. Setting in field settings as per #4 would be awesome.

BalajiDS’s picture

patch #2 is working fine for all themes(Bartik, Claro and Seven).

BalajiDS’s picture

Please ignore comment #7.
patch #2 working fine in drupal 8.8.6

sivaji_ganesh_jojodae’s picture

Not sure if empty string would be an appropriate value for data align property, maybe we remove that attribute by default.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

phenaproxima’s picture

I think we will need an issue summary update to explain the rationale for this change. Why is center alignment bad?

ckaotik’s picture

Why is center alignment bad?

We most often translate "left" into float: left;, "right" into float: right; and "center" into margin: auto. With "none", we take the item as-is, and have it flow normally based on its size and the text alignment of the container. So, at least for us, "center" is a concious decision on how the item should be displayed, thus it shouldn't be the default.

Also, why would there be a "None" setting, if we consoder "center" as the "default" (i.e. unchanged) state?

phenaproxima’s picture

frankdesign’s picture

I agree with @ckaotik in #12.

Patch at #2 applies and works perfectly to Drupal 9.0.7.

It would be a bonus if the default value could be set in the UI, but setting the default to none works perfectly for my use.

morganlyndel’s picture

Issue summary: View changes

I'm a new contributor to Drupal. I am reviewing the documentation page for writing an issue summary for an existing issue using this issue as an example. Feel free to add comments and edit. Thank you so much!

gregory.clapp’s picture

Wholeheartedly agree with @ckaotik in #12. IMO Drupal shouldn't be biased by default when None is an option.

Hopefully this patch gets accepted. Even better if the default could be set in the UI, like the view mode can be set as a default. And even better than that, if it could be configured to present the choices *before* inserting the media, rather than making my users re-edit the media every time. I wish I were in a position to be a contributor instead of just a complainer :)

scotwith1t’s picture

+1 for this change here as well. No default is a more sensible default than center for the reasons mentioned.

segovia94’s picture

Version: 8.9.x-dev » 9.2.x-dev

I also agree that the center alignment is problematic. I think this is supposed to be against the latest branch for feature requests so am changing the version to 9.2.x.

segovia94’s picture

Status: Needs review » Reviewed & tested by the community

Patch applies and works as expected.

catch’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs screenshots

Per #11 the issue could use an issue summary update - also some screenshots for before/after (the ones in #7 appear to be for a different issue).

phenaproxima’s picture

Issue summary: View changes
Issue tags: -Needs issue summary update

Updated the issue summary.

phenaproxima’s picture

To quote #4:

Completely agree with this one, the default value should be left to none. Even better if we could declare it from field settings.

And #6:

Center alignment is not a sensible default - IMO. Setting in field settings as per #4 would be awesome.

I should make clear that it is not going to be possible to configure this per field. Media embed settings are stored in the text format, not the field. So it will have to be configurable by text format. Will that be acceptable? Also, I assume we're talking about configuring which alignment will be the default choice in a given format, rather than forcing every embed in that format to use a particular alignment.

If that sounds correct, let's open a follow-up issue to add that configurability before we return this issue to RTBC.

phenaproxima’s picture

Issue summary: View changes
dflitner’s picture

Being able to set a default alignment in the text format would be perfect. Failing that, I agree that an alignment of none is a better default than center.

The patch in #2 works in Drupal 8.9.13.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

eric.chenchao’s picture

StatusFileSize
new1.35 KB

The patch in #2 will print `data-align=""`, I think this can be omitted.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

seanb’s picture

@lauriii asked me to take a look at this. The default seems to have been introduced in #2994699-15: Create a CKEditor plugin to select and embed a media item from the Media Library, but I think we might have overlooked the implications of this.

I agree with #12 that doing nothing seems to be a better default. This is also how regular image alignment works in the editor. It makes sense for media to behave the same as images as much as possible.

+1 for changing the default.

lauriii’s picture

Status: Needs work » Needs review
StatusFileSize
new2.52 KB
new1.74 KB
seanb’s picture

Status: Needs review » Reviewed & tested by the community

This looks good to me. Tests are green. RTBC!

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 29: 3099878-29.patch, failed testing. View results

lauriii’s picture

Status: Needs work » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 29: 3099878-29.patch, failed testing. View results

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

callen321’s picture

StatusFileSize
new1.46 KB

Rerolled for 9.5

callen321’s picture

StatusFileSize
new1.01 KB
new2.47 KB

Fixed fail test for 9.5 patch

_utsavsharma’s picture

StatusFileSize
new1.46 KB

As the patch in #37 was not applicable in 10.1.x. Fixed it.
Please review.

_utsavsharma’s picture

Status: Needs work » Needs review
martijn de wit’s picture

StatusFileSize
new2.47 KB

Removed an empty line for patch #37 so now patches for 9.5.x and 10.1.x are the same.

Because it are re-rolls. back to RTBC

Status: Needs review » Needs work

The last submitted patch, 40: 3099878-40.patch, failed testing. View results

martijn de wit’s picture

Status: Needs work » Reviewed & tested by the community

So:
#40 is for 9.5.X
#39 is for 10.1.X

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 40: 3099878-40.patch, failed testing. View results

martijn de wit’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new1.46 KB

please don't attach tests for a different version....
It will change the issue status...

xjm’s picture

Issue tags: -Needs screenshots

This is tagged "Needs screenshots", but I don't think it does. It's just about the default option, and does not change the presentation of any of the options.

And I, personally, click the button from "center" to "left" 80% of the time, and to "right" 20% of the time. +1 from me.

It could maybe use a small change record since this is a small user interaction change.

xjm’s picture

  • xjm committed 2fc49387 on 10.1.x
    Issue #3099878 by Martijn de Wit, lauriii, mel-miller, _utsavsharma,...
xjm’s picture

Status: Reviewed & tested by the community » Fixed

Manually tested, confirmed it works as advertised, without altering existing content or the options available.

Committed to 10.1.x. I did not backport it as it's a minor user interface/interaction change, and therefore minor-only.

Thanks everyone for working on this!

xjm’s picture

Published the CR.

wim leers’s picture

Status: Fixed » Needs work
StatusFileSize
new626.25 KB
new487.85 KB

This affects both CKEditor 4 and 5 👍

… but this introduced an authoring experience regression. CKEditor 5 will continue to show the image as centered even when it actually is not.

Before this commit
After this commit

👆 Note how there is still a left margin present, which visually suggests the embedded media is centered, even when it isn't. Only if you look at the filtered result (at /node/<NID>) will you see that it's indeed just flowing with the text.

Root cause

.ck .drupal-media {
  position: relative;
  display: table;
  clear: both;
  min-width: 50px;
  margin: 0.9em auto;
  text-align: center;
}

in core/modules/ckeditor5/css/drupalmedia.css needs to be updated to match the behavior, and we need to verify with manual testing that the different alignment choices work correctly.

wim leers’s picture

Issue tags: +CSS
ricksta’s picture

Status: Needs work » Needs review
StatusFileSize
new1.15 MB
new1.15 MB
new1.15 MB
new392 bytes

Comment #50 is correct that this commit introduced a regression in the CKEditor interface. I've removed the margin and text-align code as per Wim Leers suggestion and it does fix the issue he pointed out. First screenshot shows after the last commit was made.

After last commit

This screenshot shows the results of the code change to .ck .drupal-media demonstrating the image is left-aligned and visually appears left-aligned.

Screenshot showing image is left aligned

The screenshot below shows that the text-aligning to center is still working and there are no regressions.

No regressions screenshot

I should note that there are margins left and right of 40px that make it look like when the image is left-aligned or right-aligned, that the image is not flush with the editing window. These margins come from the user-agent style sheet. Should we override this behavior?

mark_fullmer’s picture

Status: Needs review » Reviewed & tested by the community

I have verified manually that the CSS change proposed does cause the default alignment of a media item to appear left-justified, and that center and right-justification behave as expected in the context of CKEditor 5's editing window.

As for the question about the remaining margin, visible in the second screenshot above, it's tricky: that is coming from the figure element of the drupal-media downcasted version of the element, and would not usually be present when the media item is rendered on the page. So, the margin is potentially misleading, but it's also impossible to predict whether the frontend theme will add a similar margin for the media item or not. I think the presence of the margin doesn't cause confusion about alignment, which was the original problem. So I think it should be left as-is, and sites can add CKEditor-specific CSS if they want to change it.

xjm’s picture

Fixing attribution.

I was confused to see this pop up again -- in general, when we hotfix things, the issue should either be reverted or a followup filed. We shouldn't reopen fixed issues without a revert.

Anyway, committed the hotfix to 10.1.x. Thanks!

xjm’s picture

Status: Reviewed & tested by the community » Fixed

  • xjm committed 1b41f3ba on 10.1.x
    Issue #3099878 followup by Wim Leers, ricksta, mark_fullmer
    

Status: Fixed » Closed (fixed)

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