Active
Project:
Drupal core
Version:
main
Component:
media system
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
2 Mar 2020 at 16:19 UTC
Updated:
4 Jan 2025 at 19:28 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #3
vsujeetkumar commentedI am trying to reproduce the issue with the above mentioned steps in 9.1.x however fail to add class in dropdown according to step 5(Add the following dropdown style: 'drupal-media.test-class|Test'.) and got the below error, Can someone help in this,
"The provided list of styles is syntactically incorrect."
Comment #4
bkosborneI suspect the problem here is that the "drupal-media" element is actually a CKEditor "widget", and the procedure for declaring a style is compatible with a widget has some extra steps.
Comment #5
chris burge commented@vsujeetkumar - The issue you're experiencing is #2911527: Allow dashes in Styles dropdown's element names. Give patch #57 a try.
Also, we have no patch, so setting back to 'Active'.
Comment #6
nicholasthompsonI've made a little module like this:
And I get a style option in the dropdown, however it doesn't seem to apply to the element...

I think I might need to add something to the widget config? I've read through media/js/plugins/drupalmedia/plugin.js but I'm not familiar with CKEditor plugins...
I can see `allowedContent` contains an empty classes hash...
Comment #7
patrickmichael commentedOn Drupal 8.9.1. I have patch #57 from #5 applied. Attempting to add the style
text-muted|Faded secondary textto custom styles results in the following error:The provided list of styles is syntactically incorrect.Am I missing something?
Comment #8
nicholasthompsonPatrick - you might need a
.(dot) beforetext-mutedotherwise it's only going to apply to<text-muted>elements..text-muted|Faded secondary textComment #9
patrickmichael commentedThank you Nicholas, for pointing me in the right direction. I have a custom theme based on Classy that uses the Bootstrap 4 library. I am adding Bootstrap text formatting and typography classes to the styles drop down. I did not differentiate between inline styles and styles that need to be applied to a block element.
Inline styles:
cite|Cite
code|Code
var|Variable
Block styles:
small.text-muted|Text Muted
h1.display-1|H1 Display 1
footer.blockquote-footer|Blockquote Footer
Thanks again.
Comment #10
phenaproximaComment #12
jddh commentedI think this is a really good idea -- it is currently rather difficult to apply any basic styling to Media in a CKEditor field, which is a rather fundamental requirement for using Media at all.
Comment #14
phma commentedThe media widget discards any classes added by CKEditor on 'downcasting'. That's why using a custom module like in #6 doesn't work.
This patch should fix this.
Comment #15
phma commentedComment #16
phma commentedFixing code styling issue and using the latest branch.
Comment #17
vsujeetkumar commented@phma Interdiff is missing in #16, It will help to understand what the changes has been done.
And this patch needs Reroll, as it has changes in core/modules/media/js/plugins/drupalmedia/plugin.es6.js file.
Update es6 file then compile the code with yarn.
Comment #18
gauravvvv commentedFixed CS errors.
Comment #19
lan commentedHi,
I have added the patch to the site, I am able to apply the class to the style dropdown at CK editor, but the class not able to add to the image source after drupal-media tag.
Comment #21
kathyjg commentedI have same issue as Lan, I have applied the patch, I can add the class to the style dropdown options, however when I select the style for my embedded media document it does not apply it. I just want to provide an option for my client to be able to bold or feature certain documents that are embedded into a page with their media library.
Comment #22
akhildev.cs commentedHi, tried patch #18,
I am also able to add 'test-class' from dropdown styles.I added an image from the media library and then selected 'test class' from the style dropdown. But class is not applied to the added media.
CKEditor source mode shows only '<'drupal-media'>' after the patch is applied.
Comment #23
wim leersComment #24
abhijith s commentedApplied patch #18 but its not adding class attribute to
drupal-mediatag.After patch:

Comment #27
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #28
wtrv commentedRe-rolled patch against 9.5.x
Comment #29
wtrv commentedComment #31
sclsweb commentedI tested the patch from #28 with CKEditor 4, using a style configured as "drupal-media.img-thumbnail|Imageborder," and it did not add the class to drupal-media.
Comment #32
alinouman commentedI'm also looking a solution for it.
Comment #33
alinouman commentedI fixed it in a different way
Comment #34
wim leersThis will never get fixed for CKEditor 4.
For CKEditor 5, this is blocked on https://github.com/ckeditor/ckeditor5/issues/14274#issuecomment-1744624793.
Comment #35
wim leers#3347721: [Style] Warn the user about styles for unsupported elements just made this easier to discover 👍
Comment #36
marc.groth commentedFor those wanting to implement this sooner... This module seems to be very promising: https://www.drupal.org/project/ckeditor5_inline_styles
Comment #37
bkosborneI don't think this is blocked upstream. The upstream issue indicates that each plugin that provides its own block level widget needs to be updated to integrate with the Styles plugin, like they had to do for Table widgets. There's no action in the upstream issue we're waiting on. I think we just need to update our custom plugin's code to allow for this.
Comment #38
bkosborneI had to do this for a custom plugin of mine. I wrote up some important tidbits on how to do it here.
Comment #39
chris burge commentedWhen I asked around among colleagues today, I was pointed to this blog post: https://dev.acquia.com/blog/drupalelementstyle-add-styles-drupal-media-c....
@bkosborne - Is this solution functionally equivalent to the plugin you authored?
Comment #40
mortona2k commentedThe instructions in that post are working, I was able to add data-attribution to the wrapper for a remote video.
This ticket looks relevant: https://www.drupal.org/project/drupal/issues/3406020