Closed (outdated)
Project:
Drupal core
Version:
11.x-dev
Component:
media system
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
3 Jun 2021 at 17:38 UTC
Updated:
8 Mar 2025 at 23:38 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
prudloff commentedThe attached patch adds a boolean setting (enabled by default) on the filter.
(I guess another solution could be to disable captioning when the Caption filter is not enabled.)
Comment #3
gauravvvv commentedFixed custom command failed. Attached interdiff for the same.
Comment #4
pameeela commentedThanks @prudloff for reporting and @Gauravmahlawat for the patch. Updating the category because adding a new feature is a feature request rather than a bug :)
Comment #6
joshua1234511Tested the feature request with the steps mentioned in Issue summary.
Applied the Patch provided #3
Tested on v9.4.x-dev
- Patch successfully applied
- Checkbox provided to enable disable the the Caption
The JS still needs some work, the entire caption field freezes
Code Review.
editor.config.DrupalMediaLibrary_enableCaptioningNot defined.This needs to be set and passed in getConfig
media schema needs to be updated
Comment #8
joshua1234511Create a issue fork, Applied the patch and updated the code
- This will enable/disable the caption checkbox entirely form the form.
https://git.drupalcode.org/project/drupal/-/merge_requests/1893/diffs#c9...
- Passed the variable value for DrupalMediaLibrary_enableCaptioning
https://git.drupalcode.org/project/drupal/-/merge_requests/1893/diffs#86...
- Updated the schema
Pending/Todo
The Js code still needs some review/fix
Comment #10
cgmonroe commentedAnother way to do this is to just change the editable caption selector to include a check for a data attribute on the figcapture tag. E.g.:
This :not([data-no-edit']) part means that if the twig template uses:
The caption will not be editable.
Comment #11
cgmonroe commentedWith a little research, I found a way to modify the editable caption selector without patching core.
Basically, you need a custom bit of JS to run when CKEDITOR is initialized. This can be in your theme (the one used for editing) or added via a custom module. Here's the basic JS to run:
Update your template with figcapture to include the data-no-edit attribute to prevent caption editing.
Comment #14
gauravvvv commentedComment #16
gaëlgWith CKEditor 5, included in Drupal 10 core, it looks like media caption is already not editable. CKE4 is unsupported and needs a contrib module.
Comment #17
prudloff commentedCKE5 does allow editing captions but only if the "Caption images" filter is enabled.
So site builders can choose if the caption can be edited.