Problem/Motivation

Unthemed Edit Media button:
Unthemed Edit Media button

See #3092779-10: media_library.theme.css is being called despite it no longer existing

When the Media Library styles were moved into the theme layer, the fact that one stylesheet was being added in DrupalMedia.php was overlooked. Consequently, the "Edit media" button is now unstyled in the Seven theme.

Proposed resolution

Add styles from Media Library for the Edit Media button in the seven theme, or in the Media Library module.

Regression fixed

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

oknate created an issue. See original summary.

phenaproxima’s picture

Title: Media Library Media Embed "Edit Media" styles should be restored in Seven theme » [regression] Restore styling for embedded media edit button in Seven theme
phenaproxima’s picture

Status: Active » Needs review
StatusFileSize
new452 bytes

Not sure what else is needed here. I suppose that this is bringing in more styles than we'd ideally like, so we could split out the CSS into multiple files, but that seems out of scope here.

oknate’s picture

Status: Needs review » Needs work

ckeditor_stylesheets is for the main theme, not for the admin theme. See _ckeditor_theme_css(). It's looking in Bartik and the themes it extends, not in Seven.

seanb’s picture

I too ran into the issue for #4. It seems every theme should have a copy of media-library.css for the ckeditor styles, even if the media library is only used in the admin theme. Should we add it to bartik and umami for now to fix this?

It sucks, but I guess that is what we have to deal with. I really think we should consider adding more styles back into the module. It is a separate issue, but I personally think overriding existing styles is the lesser evil compared to the amount of hooks and CSS a theme now has to copy to make the library look good. Apparently even in the admin theme. I don't expect anyone to understand this, since even I really don't know how to explain this to people.

oknate’s picture

Here's a fix, but I think we should look for a better solution. Unfortunately hook_keditor_css_alter() doesn't work at the theme level.

/**
 * Implements hook_ckeditor_css_alter().
 */
function media_library_ckeditor_css_alter(array &$css, Editor $editor) {
  if (!$editor->hasAssociatedFilterFormat() || \Drupal::theme()->getActiveTheme()->getName() !== 'seven') {
    return;
  }
  if ($media_embed_filter = $editor->getFilterFormat()->filters()->get('media_embed')) {
    if ($media_embed_filter->status) {
      $css[] = 'core/themes/seven/css/theme/media-library.css';
    }
  }
}

1) _ckeditor_theme_css should support admin themes, this could be an issue blocking this.
2) We don't want to add everything from media library anyway. We only need enough styling for the edit button.

seanb’s picture

So I just had a quick call with phenaproxima and lauriii about this. The real issue here is indeed that admin themes can't provide styles for the ckeditor. For that we can do the following things:

  1. Provide a ckeditor stylesheet in the media library module (basically add back the missing stylesheet mentioned in #3092779: media_library.theme.css is being called despite it no longer existing) to provide the seven styles for the buttons. The drawback is other admin themes will also get the seven styles for the media library without being able to override it. It can however be overridden from frontend themes (same as now).
  2. Remove the buttons in CKEditor for now. Users can still edit the alt text etc by right clicking the media item. This will make media items show less consistent, but will provide a consistent experience for different admin themes.
  3. Solve the issue of allowing admin themes to add CSS to CKEditor. Not sure if we can actually solve this in this release though. That seems unlikely.

Options 1 or 2 are most feasible for the short term, but they both have serious drawbacks. We probably need a product manager to make the final call on this.

That still leaves my other concern about the overall issue that themes need to copy a lot of hooks, templates and CSS to their own themes to make the media library look good. For that we can and should provide a handbook page and a contrib module for the short term to make it as easy as possible.

oknate’s picture

StatusFileSize
new2.62 KB
new2.99 KB

This will fix it when the FE theme extends Classy, including Bartik, in other words, on a Standard install.

oknate’s picture

Status: Needs work » Needs review
seanb’s picture

Status: Needs review » Needs work

The last submitted patch, 8: 3092779-8.patch, failed testing. View results

oknate’s picture

StatusFileSize
new1.05 KB
new4.04 KB

Fixing test failure in #8.

oknate’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new2.35 KB
new441.45 KB
new428.45 KB

Here's a different approach: Updating media/css/plugins/drupalmedia/ckeditor.drupalmedia.css, which is actually already dealing with this edit button.

This is a version of approach #7.1.

oknate’s picture

StatusFileSize
new613 bytes
new4 KB

Fixing one errant unnecessary style in #12.

We need feedback on these two approaches, in #13 and #14.

Approach #14 updates all FE themes that extend Classy to provide themed edit buttons for media embeds in the CKEditor.

oknate’s picture

seanb’s picture

As mentioned before we had a talk with lauriii and phenaproxima about this, and fixing it in the module or classy is the easiest solution for now, but probably problematic from a theming perspective. The BC implications of doing it in the module or in classy might come back to bite us in the ass.
My preference would be to solve it properly via #3092828: Allow admin themes to specify ckeditor_admin_stylesheets in their info file for admin components in ckeditor., so Seven and Claro can provide their own styles for admin elements within CKEditor. But ultimately it is a PM decision.

lauriii’s picture

Should we at least ship with some styles as part of the core themes?

oknate’s picture

+1 to that. I think a large percentage of users wouldn't bother to theme it, and we'd be doing the community a great favor to provide a sensible default here.

phenaproxima’s picture

Should we at least ship with some styles as part of the core themes?

+1 for this as well.

lauriii’s picture

Status: Needs review » Needs work

Sounds like we should create a revision of #15 which has the changes moved to Claro, Seven, Bartik, and Umami.

chris burge’s picture

By process of elimination, we're left with the second patch from #15.

Option 1: CSS should be provided by admin themes, Seven and Claro
Unfortunately, admin themes cannot specify stylesheets for CKEditor.
hook_ckeditor_css_alter() cannot be implemented by a theme.
We could implement hook_ckeditor_css_alter() in Media, but then there's no point of storing the stylesheets in the various admin themes. It'd be housed with Media. At that point, we're basically at Option 3, below.

Adding it to Bartik and Umami isn't useful as those are demo themes. They're unlikely to be used on a production site, even as a base theme.

Option 2: CSS should be added to classy
With Classy moving to contrib, #3050389: [META] Remove dependency to Classy from core themes, this seems like a nonstarter.

Option 3: CSS should be provided by the Media module.
This is what we're left with. And I don't see this as a bad option. Modules provide their own CSS all of the time.

chris burge’s picture

Status: Needs work » Needs review
StatusFileSize
new1.56 KB

Whereas a user is able to click on the icon, this patch adds pointer behavior to indicate an interaction to the user.

  border-radius: 20px;
  background-size: 13px;
  text-shadow: none;
  font-size: 0;
+ cursor: pointer;
}

drupal-media .media-library-item__edit {
  right: 10px;

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

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now 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.

priyanka.sahni’s picture

Assigned: Unassigned » priyanka.sahni
priyanka.sahni’s picture

StatusFileSize
new381.77 KB
new388.07 KB
new399.08 KB
new389.72 KB
new394.08 KB
new394.2 KB

Verified and tested by applying the patch on Drupal 8.9 and 9.1.It looks good to me.Can be moved to RTBC.

Steps to test -
1. Go to the admin site.
2. Go to admin/appearance
3. In the Administration theme , select Claro/Seven.
4. Go to admin/modules , enable Media, Media Library.
5. Go to admin/config/content/formats
6. In the text editor , from the Available buttons add the media type in the Active toolbar.
7. In the Enabled filters , enable these filters Align images and Embed media and click on save configuration.
8. Go to Article page.

Before Patch 9.1 -
BeforePatch

Before Patch 8.9 -
BeforePatch

After_Patch_9.1_Seven -
After Patch

After_Patch 9.1 Claro -
After Patch

After Patch 8.9 Seven -
After Patch

After Patch 8.9 Claro -
After Patch

priyanka.sahni’s picture

Assigned: priyanka.sahni » Unassigned
chris burge’s picture

Version: 9.1.x-dev » 8.9.x-dev
Status: Needs review » Reviewed & tested by the community

@priyanka.sahni - Thanks for your thorough review.

Because this is a bug (and not a new feature), I'm setting the version back to 8.9.x-dev.

Per #25, moving to RTBC.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 22: 3092795-22.patch, failed testing. View results

chris burge’s picture

Status: Needs work » Reviewed & tested by the community

Setting back to RTBC. Test failure was an intermittent branch test failure and is unrelated to this patch.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 22: 3092795-22.patch, failed testing. View results

chris burge’s picture

Status: Needs work » Reviewed & tested by the community

Setting back to RTBC. Test failure was an intermittent branch test failure and is unrelated to this patch.

alexpott’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +Needs frontend framework manager review

@Chris Burge it looks like you've rtbc'd your own work here - sorry if I've misunderstood that.

But also the solution in #22 appears to directly go against the consensus built by #20. As @lauriii is the front end framework manager we need his +1 that the solution in #22 is okay.

chris burge’s picture

@alexpott - I did jump the gun. @priyanka.sahni reviewed and stated RTBC (w/o changing the status). I should have requested she move the status herself.

Re the consensus, see #21. Admin themes cannot specify stylesheets for CKEditor, so Seven and Claro are out. Umami is a demo theme, and fixing this only in Bartik doesn't help anyone. So.. patch #22 uses the Media module to provide the CSS. (If admin themes could provide CKEditor stylesheets, that would, of course, be a game changer.)

phenaproxima’s picture

volkswagenchick’s picture

Adding NorthAmerica2021 and Easy Out of the Box tags for visbility.

DrupalCon NA is April 12-16 with a focus on EOOTB on Wednesday, April 14.
Thanks

chris burge’s picture

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

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.

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.

larowlan’s picture

Status: Needs review » Postponed (maintainer needs more info)
Issue tags: +Bug Smash Initiative

Does this impact CKEditor 5? With CKeditor 4 moved to contrib should this issue be moved to contrib

andrew.wang’s picture

StatusFileSize
new1.56 KB

Re-rolled #22 for Drupal 9.5.

EDIT: This didn't work. I ended up copy-pasting the styles into a CSS file defined as ckeditor_stylesheets.

nuuou’s picture

StatusFileSize
new1.47 KB

Re-rolled Patch #41 with CKEditor 4 in Contrib

EDIT: Looks like I left an incorrect filepath to an image in this patch. Need to adjust that.

matia.ward’s picture

StatusFileSize
new1.48 KB

Fixed the icon path.

nuuou’s picture

StatusFileSize
new1.48 KB

#43 is not applying for me for some reason, attaching a new patch that should be identical to #43.

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

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

chris matthews’s picture

There is a patch in #44, however, @larowlan's questions in #40 still need to be answered, which is why the status for this issue is Postponed and not Needs Review.

Does this impact CKEditor 5?
With CKeditor 4 moved to contrib should this issue be moved to contrib?

acbramley’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)

This came up again in Bugsmash today. It has been over a year since this was set to PMNMI and no further information has been provided.

The seven theme no longer exists in core and I can't see that CSS file either that the patch is changing. Therefore I'm marking this as Closed (outdated).

Please feel free to open a new issue with steps to reproduce this bug from a fresh drupal installation.