Problem/Motivation
In #3222757: [drupalImage] Make image alt text required or strongly encouraged the ability to mark an uploaded image as "decorative" using a toggle switch was provided for the drupalImage CKEditor 5 plugin. No comparable toggle is present on the drupalMedia CKEditor 5 plugin.
Justification for Drupal media
The ability to mark an image added from the Media Library as "decorative" should happen in the context of placing the image on the page, rather than as metadata on the media entity itself, since the nature of the image being decorative is dependent on context, not content. Per WCAG's guidelines, the decision whether to treat an image as decorative or informational is a judgement that only the author can make. It would be helpful to offer the same one-click option that Inserted images have to the Media images.
Current behavior
Insert Drupal Media allows the editor to override the existing alt text, but does not offer a toggle or even messaging explaining how to mark the image as decorative. Entering two quotation marks will cause the image to render without an alt tag, but this could be improved by adding a toggle that behaves with the same UX as the existing drupalImage implementation in #3222757: [drupalImage] Make image alt text required or strongly encouraged
Expected usage / Sample test steps
1. Installing from the "Standard" profile, enable media_library
2. Under admin/config/content/formats/manage/basic_html, add the "Drupal Media" plugin to the CKEditor toolbar
3. Enable the "Embed media" text format filter and save the text format.
4. Create a node of type "Basic page."
5. Using the Basic HTML toolbar, add an image using the "Media library" plugin that is now present in the toolbar.
6. After the image is inserted into the rich text area, click on it.
7. Click the "Override media image alternative text" icon in the balloon ribbon.
8. Set the "This is a decorative image" toggle to "On"
9. Click the "Save" checkmark in the CKEditor balloon modal.
10. Save the page.
11. View the page. The image should render with alt text in the page source reading alt=""
Proposed resolution
Add a similar toggle to the alternative text contextual bubble for Media Library images in the CK Editor 5 WYSIWYG, so the user can either provide an alternative for the default alt text, or disable it completely.
User interface changes
Match the user interface already established in the drupalImage plugin, providing a toggle switch adjacent to the text override within the existing "Override alternative text" option:
Baseline functionality of existing drupalImage decorative toggle

Staged new functionality for drupalMedia decorative toggle with alt text override

Release notes snippet
Ckeditor5 now allows for marking images as decorative, "conveying no additional information beyond the content surrounding them". This helps improve accessibility.
| Comment | File | Size | Author |
|---|---|---|---|
| #47 | 3313616-nr-bot.txt | 90 bytes | needs-review-queue-bot |
| #43 | 3313616-nr-bot.txt | 90 bytes | needs-review-queue-bot |
| #40 | 3313616-nr-bot.txt | 90 bytes | needs-review-queue-bot |
| #37 | media-alt-text.gif | 416.12 KB | mark_fullmer |
| #34 | drupalmedia-decorative-toggle.gif | 934.22 KB | mark_fullmer |
Issue fork drupal-3313616
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3313616-insert-drupal-media
changes, plain diff MR !6391
Comments
Comment #2
cilefen commentedComment #3
wim leersNote that CKEditor 4 did not support this; that's why this is not yet supported in CKEditor 5 either.Looks like it was — quoting
\Drupal\media\Form\EditorMediaDialog::buildForm():— two double quotes without any content).'),
But it clearly was pretty obscure.
Note that you can do the same in CKEditor 5, there is just no UI string like the above.
The proper solution would be to add the same decorative image toggle that we added for images in #3222757: [drupalImage] Make image alt text required or strongly encouraged.
Marking because it technically is a regression, albeit one that has a work-around. The real regression here is only the user not being informed of how they can mark the image media as decorative.
Comment #4
bnjmnmI'm not so sure this qualifies as a regression. The behavior is no different from how it is done in CkEditor 4
It could be considered a mayb-regression since the experience was improved for images and hasn't yet been improved for media. This could be seen as introducing a new violation of Nielsen Heuristics #4, consistency and standards, but there's arguably several other differences between the media and image experiences already.
I absolutely think the media alt text should get the same improved UI that images did. I'm less sure it needs to be categorized as a regression that was introduced as nothing got worse. Rather something adjacent to it got better.
Since Drupal 9/CKEditor 4 is still supported for a while, it would be good to have an additional issue that updates the dialog to include instructions regarding decorative images. It provides better information to CK4 users and could be a reasonable fallback if the full CKEditor 5 implementation is stalled.
I'm going to remove the regression tag, and if there's a strong sentiment to bring it back that can happen. I still think this should get a high priority but I want to avoid miscategorizing.
Comment #5
mgiffordCould be useful to properly manag wcag sc 1.1.1.
Comment #9
mark_fullmerThe merge request above, modeled on the same UX as the drupalImage plugin, provides the ability to toggle decorative alt text for the drupalMedia, while still preserving the ability to use or override the default alt text from the Media entity.
Comment #10
smustgrave commentedEven though it's a task seems like the kind of feature that could/should have test coverage.
Moving to NW for failures in MR though.
Comment #11
mark_fullmerYes, based on the comment thread, I'm not sure that "Task" is the right categorization. I'm reading arguments in favor of classifying this as a 'major regression' (bug), and on the other hand, the original issue description reads more like a proposed enhancement.
Regardless, yes, this should have test coverag! I've added that in the recent commits.
I've used Prettier to update the syntax in the JS, but I'd like input from others about the spell checking failure: cspell is complaining about the unknown words "switchbutton" and "switchbuttonview". But those words already exist elsewhere in Drupal core code (see /modules/ckeditor5/js/build/drupalImage.js). So I don't want to inappropriately increase the scope of this change by modifying core/misc/cspell/dictionary.txt, unless others feel that should be done now.
Setting back to "Needs Review" for input on that.
Comment #12
charles belovIt appears from the demonstration animated gif of the decorative image toggle that the default is decorative. The default would best be non-decorative, requiring that the editor assertively choose that the image is decorative.
Please clarify as to whether this animation shows the default or reflects an image that was previously set to decorative.
Comment #13
mark_fullmerThe GIF is on a loop that makes it a little confusing! The default is non-decorative. It's an opt-in thing, for sure!
Comment #14
sandeep_k commentedI've Tested this MR- MR !6391 mergeable on Drupal version- 11.0-dev. The patch was applied successfully and it looks good to me.
Testing Steps:
Testing Results:
After applying the patch, the option to mark the image as decorative is available now. Sharing after result.
Comment #15
smustgrave commentedTested this out with my accessibility hat on, according to https://www.w3.org/WAI/tutorials/images/decorative/
Confirmed using the ANDI toolbar tester that using this does get flagged.
Comment #16
mark_fullmerThanks for reviewing, smustgrave! Can you provide clarification on what needs work? To my understanding this is designed to render
alt=""on the page when the "Decorative" option has been selected, and based on my testing, that is what happens. That seems to match the WAI guideline referenced above. Is that not happening for you?As far as I can tell, this implementation's behavior is identical to the existing core behavior for the drupalImage widget.
Comment #17
smustgrave commentedI can retest but I wasn’t getting any alt text.
Comment #18
mark_fullmerHere are the steps I was using to test, for comparison:
1. Installing from the "Standard" profile, enable
media_library2. Under admin/config/content/formats/manage/basic_html, add the "Drupal Media" plugin to the CKEditor toolbar
3. Enable the "Embed media" text format filter and save the text format.
4. Create a node of type "Basic page."
5. Using the Basic HTML toolbar, add an image using the "Media library" plugin that is now present in the toolbar.
6. After the image is inserted into the rich text area, click on it.
7. Click the "Override media image alternative text" icon in the balloon ribbon.
8. Set the "This is a decorative image" toggle to "On"
9. Click the "Save" checkmark in the CKEditor balloon modal.
10. Save the page.
11. View the page. The image should render with alt text in the page source reading
alt=""Comment #19
smustgrave commentedAh so I tested with the just the regular image button, which needs a follow up as the decorative feature doesn't add an empty alt text.
The media feature works fine only concern was that without this ticket not sure I would of known to go under the "Override alt" button to turn decorative. Could be just me though
Put in review for other thoughts
Comment #20
mark_fullmerComment #21
mark_fullmerComment #22
mark_fullmerThanks! It would be great to hear from others. Specifically....
Placing this toggle within the "Override alt" button (i.e., the eyeball with a strike through it) is simply following precedent established for the drupalImage plugin (#3222757: [drupalImage] Make image alt text required or strongly encouraged). I've updated this issue's description to reflect that this proposes to replicate that UX, not introduce a new UX.
Comment #23
smustgrave commentedDon't want my comment to be the blocker.
Opened a follow up for #19 #3421421: [drupalImage] Decorative image toggle doesn't add empty alt
Did test the MR and verified using media library button it works as expected.
So after the follow up probably good to self RTBC.
Comment #24
itmaybejj commentedMy advice, as someone who teaches people what "decorative" means, is to pick a field label that does not assume understanding what "decorative" means -- something that inherently teaches what the action does, and discourages clicking the button unless you know what you are doing.
Something like "This image contains no meaningful information and should be ignored by screen readers"
Decorative Image Widget uses "This image is decorative and should be hidden from screen readers." It includes a link, but that includes some tomfoolery with aria-labels, since you can't have a link in a label.
Comment #25
itmaybejj commentedAnother suggestion -- I suggest flipping the order of the fields, so that the dynamic textfield comes after the toggle.
Two reasons --
Comment #26
simohell commentedOne more thing about showing/hiding content:
Since the decorative image does not have an alt text it might be a good idea to hide the default alt-text as well as the override field. In my opinion it would be better express the effect of marking an image decorative.
Comment #27
wim leersdrupalImageplugin, to avoid confusion/inconsistency. It's totally possible that it can/should be improved. But that'd require a separate issue then. Can you please open that? 🙏Review
drupalImageanddrupalMedia, please add GIFs for both to the issue summary.drupalImage, it currently does not.Comment #28
mark_fullmerThanks for the question!
The new CSS staged in the MR (i.e., targets for
.ck.ck-responsive-form.ck-media-alternative-text-form--with-decorative-toggle) are added tocore/modules/ckeditor5/css/drupalmedia.cssto replicate the behavior of differently namespaced CSS fromcore/modules/ckeditor5/css/image.css(i.e.,.ck.ck-responsive-form .ck.ck-text-alternative-form__decorative-toggle).These implementations for drupalImage and drupalMedia could potentially be made D.R.Y. That would require consolidating the alt text switchbutton CSS into a single file and then adding that to both libraries in
modules/ckeditor5/ckeditor5.libraries.ymlComment #29
wim leersThat sounds great! 👍 Let's do that?
Comment #30
wim leersFYI: #3419894: [drupalImage] Rename "Text alternative" field label to "Alternative text" just landed, so we should match that text now.
Comment #31
aaronmchaleOne thought, based on the GIF in comment #9, I wonder if the toggle should also hide the default alt text, because with that visible but the override option hidden, it kind of implies that the default alt text will be used. I think it would be better to hide the default alt text as well, because once the image is set as decorative, the default alt text is no longer relevant.
Comment #32
mark_fullmerBefore we proceed with changes, I think we need to revisit the assumption that the UX, and therefore the text and other elements, is in fact the same/consistent between drupalImage and drupalMedia. Even prior to this issue to add the decorative toggle, drupalImage and drupalMedia were designed differently.
The main functional difference is that, in drupalImage, there is no default alt text to start with. Someone must enter alt text in this UI for the image to have alt text, or they must indicate the image is decorative.
In drupalMedia, alt text from the media entity is used if no override is supplied. Per the current logic, leaving the "Alternative text" field empty will result in the media entity's alt text being used.
So, in drupalImage, this interface is the method for *entering* alt text. In drupalMedia, this interface is the method for *overriding* default alt text.
Given this, I think we must do one of the following:
1. Conclude that these serve different purposes and allow divergence in field labels: drupalImage remains "Alternative text," while drupalMedia is "Override default alternative text" or something to that effect. Screenshot:
2. Rework the existing logic of the drupalMedia implementation: the media entity's alt text would *prepopulate* the "Alternative text" field. Screenshot:
Comment #33
mark_fullmerMy own answer to this question, upon reflection, is that #1 is the less confusing UX, even if it will be different from drupalImage. If we were to do #2, a user who wants to restore the default media entity alt text after overriding it would be hard-pressed to figure out how to do that.
Comment #34
mark_fullmerComment #35
mark_fullmerThis is addressed, per the latest commits!
The label for the decorative toggle now reads "Decorative toggle," matching that of drupalImage.
This is done! See summary.
Comment #36
smustgrave commentedTrying to keep up with this.
Believe there are 2 open threads on the MR if they could be closed or answered. Left 2 comments/questions myself.
Comment #37
mark_fullmerThanks for the further input, smustgrave & Wim! I've addressed all of the comments and marked as resolved all but one, which I've left an explanation for, and will defer for someone else to confirm the rationale for that business logic.
Back to "Needs review," with updated screenshot in the original issue description!
Comment #38
mark_fullmerComment #39
mark_fullmerComment #40
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #41
mark_fullmerMoving this back to "Needs review," as I believe the Needs Review Queue Bot's analysis of this no longer applying is incorrect?
Comment #42
smustgrave commentedBelieve all feedback has been addressed in the MR.
Comment #43
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #44
mark_fullmerI've updated the merge request to incorporate the latest changes from 11.x. Tests are passing again, so I'm setting this back to the "RTBC" status previous to the Needs Review Queue Bot.
Comment #45
wim leers#32++
The second proposal in #32 could be problematic depending on how it is implemented: if this would result in the
altattribute actually getting populated even when the alternative text is unchanged, it'd cause updates on the Media entity to not propagate down. That'd be a regression compared to today.But … given #33, that won't be a problem 😄👍
Review
This looks great! And 98% ready. The last 2% are a few small concerns I have wrt the UI strings and documenting the meaning of
""plus the difference compared to how this works indrupalImage🙏 Once those are addressed, I'll happily re-RTBC :)Comment #46
mark_fullmerAwesome! These should all be addressed via the latest commits. Setting back to "Needs Review"!
Comment #47
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #48
mark_fullmerMerge conflicts resolved. Setting back to "Needs Review" :)
Comment #49
smustgrave commentedFeedback appears to be addressed but would like @Wim Leers thumbs up too.
Comment #50
smustgrave commented@Wim Leers any objection to marking RTBC?
Comment #51
smustgrave commentedBelieve this one is still good to go.
Comment #52
alexpottI think this change needs both a change record and a release note. A frontend framework manager would be better placed to review the code... so once those exist
Also I used the functionality and looked at the source it was
width="1600" height="900" alt loading="lazy"... do we care that it is notalt=""which is what the https://www.w3.org/WAI/tutorials/images/decorative/ documents? I checked this is not what my browser is doing... it looked the same if I use curl. Reading https://stackoverflow.com/questions/75256822/accessibility-alt-or-alt-fo... makes me this this is just fine. phew.Comment #53
mark_fullmerChange record drafted at https://www.drupal.org/node/3442726
Setting back to "Needs review"
Comment #54
smustgrave commentedChange record looks good so removing that tag.
Added release note to the summary
But MR appears to need a manual rebase.
Comment #55
mark_fullmerThis has been rebased of the last commit on 11.x. Setting back to "Needs Review."
Comment #56
smustgrave commentedBelieve all points have been addressed. Left open for additional reviews for about a month so going to mark.
Did retest and still behaving as advertised.
Comment #61
nod_Committed and pushed 8e56f38400 to 11.x and 9c9c730ab6 to 11.0.x and a770ef7b65 to 10.4.x. Thanks!