Problem/Motivation
The filter module from core provides a filter to display image captions and align images: FilterCaption. This filter in itself does not requires the DOM element to be an <img>
tag, but in tips, description, comments etc. it mentions the term image. Although, in short description it mentions that it can be used elements other than image:
return $this->t('You can caption (data-caption="Text") and align images (data-align="center"), but also video, blockquotes, and so on.');
But when this is used by the CKEditor module in 'drupalimagecaption' plugin (DrupalImageCaption and ckeditor/js/plugins/drupalimagecaption/plugin.js), it restricts its usage to just images. Although with few changes, this plugin can be generalized to all elements. By doing this, we are saving a lot of code from being replicated by modules which want to provide a similar caption/align features (for instance entity_embed, and maybe video also).
Proposed resolution
First task is to generalize the FilterCaption
documentation so that it uses the term 'entity' instead of 'image' and modify/add examples to explain that div will work for elements other than image.
Next task will be to generalize the CKEditor plugin to remove its dependency on img element. Also, in case we do this, we'll want to rename 'drupalimagecaption' to 'drupalentitycaption' or something similar.
Since this filter is used in a couple of tests also, they will also need to be changed, but that should be as simple as changing the name of the class.
Remaining tasks
Write a patch.
Test it.
User interface changes
None.
API changes
None.
Comments
Comment #1
cs_shadow CreditAttribution: cs_shadow commentedComment #2
Dave ReidComment #3
Wim LeersLet me start by saying that I'd love to have this also.
But — sadly — AFAIK this can't be done. Please see #2284689-6: How can other modules that add WYSIWYG content reuse the data-caption and data-align attributes? and #2284689-9: How can other modules that add WYSIWYG content reuse the data-caption and data-align attributes? for my explanation, plus the upcoming explanation from a CKEditor developer.
Marking as postponed for now, until we get the definite confirmation from a CKEditor developer that this is impossible. If it turns out to be possible after all, we can reopen this. If it's confirmed to be impossible, we can close this.
Comment #4
Wim LeersTempted to close this per #2284689-10: How can other modules that add WYSIWYG content reuse the data-caption and data-align attributes?, but keeping as a feature request to be considered for a future version for now.
Comment #9
Wim LeersI was tempted to close this in #4, >2 years ago. Now actually closing.