Problem/Motivation
(This applies to embedded media as well as entity_embed, but let's discuss in one place.)
Editors can embed media/entities in ckeditor in a view mode of their choice, also edit some parts like caption.
Rendering that embedded entity in ckeditor has some challenges:
* For technical reasons, the rendered entity sometimes breaks in ckeditor (attachments ignored, so different theme / css, no js, so e.g. blazy images are broken)
* For conceptual reasons, sometimes we do not want the entity rendered like in "frontend". E.g think of a moving slideshow that only distracts editing. ("WYSIWYM, not WYSIWYG")
Details are splattered across different issues:
* #2844822: The preview in CKEditor does not use the same Twig template as the one on the front end (default theme)
* #2882866: Provide a preview display setting for use in WYSIWYG editors, improves authoring ergonomics
General considerations
suffixed preview view modes
The first question clearly is "does preview differ from view".
Assuming "yes" for reasons stated above, the information "we are in preview" has to take effect somewhere in our pipeline between entity+viewmode and the final render-array/HTML.
Other considerations:
* If we make this a developer-only thing, we exclude sitebuilders and/or the long tail of very-low-budget-sitebuilding-only projects.
Some approaches:
* Have alter hooks (e.g. for view-mode, render-array, theme-template) (This can be combined with one of the other approaches)
* Have preview view modes (#2882866: Provide a preview display setting for use in WYSIWYG editors, improves authoring ergonomics proposes one configurable view mode) which rises new questions:
- as we can embed different view modes, we'd need one preview-view-mode for each (or an other way to distinguish them)
- (one way to distinguish view modes might be a editable dropdown like the editable caption.)
- the UI to configure these preview-view-modes should integrate with the UI to select the embeddable view modes to ensure consistency
* We can have mapped preview view modes where we configure a mapping like "to preview foo, use bar" (and must have UI and validation that ensures the mapping makes sense)
* We can have suffixed preview view modes: To preview view mode "foo", look for a view mode "foo__preview". (In the UI, add links to create such a view mode, and on that view mode's config/display config, inform sitebuilder that this is a preview view mode.)
* Add a preview entity wrapper: To view embedded media, wrap the media entity in a "Embedded media" (different!) entity that is just a wrapper, may contain overrides, and can not saved. That entity type has some magic, so that unconfigured view modes fall back to media view modes. (Compare and consolidate the similar approach in #3023807: Override media fields from the reference field. There we have ReadOnlyMedia that extends and wraps Media.)
Remaining tasks
TBD
User interface changes
TBD
API changes
TBD
Data model changes
TBD
Release notes snippet
TBD
Comments
Comment #2
geek-merlin(Although i made a proposed resolution, i'd say let's keep this issue focused on comparing different approaches. So to work on an approach, let's open a new linked issue)
Comment #3
geek-merlinComment #5
phenaproximaAdding #3072317: CKEditor embedded media previews do not render with attached assets as a related issue.
Comment #6
xjmComment #7
geek-merlinAlso "Meta" is more what i meant.
Comment #8
geek-merlinCleaned up and clarified.
Comment #9
geek-merlinI have conceptually gone through the preview entity wrapper option, which i first favored. Not anymore.
It would need a lot more code and conceptual shift thatn i thought, without bringing so much win.
Compared to suffixed preview view modes, which i now favor.
Comment #10
dercheffeIn my use case I want to add images (core media entities, using Drupal 8.8.1) and want to handle them with blazy module including a colorbox switcher to enlarge images if user clicks on the thumbnail image. The blazy image doesn't render. I tried to solve the problem when I defined a paragraph type (e.g. "text with an image left","text with an image right" etc), but the UX is not as good as embed media in CKEditor directly. So it would be great to have an opportunity to render an view mode for embed entities in CKEditor additionally.
When defining a text format, it's possible to add a Default view mode in the embed media settings already. I would vote for a second field called e.g. mode to view in editor where user can choose the view mode of his taste for preview in ckeditor.