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

geek-merlin’s picture

(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)

geek-merlin’s picture

Issue summary: View changes

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

phenaproxima’s picture

xjm’s picture

Title: (Policy, no patch) Preview embedded media / entities in ckeditor » [Policy, no patch] Preview embedded media / entities in ckeditor
Category: Task » Feature request
geek-merlin’s picture

Title: [Policy, no patch] Preview embedded media / entities in ckeditor » [Meta] Preview embedded media / entities in ckeditor

Also "Meta" is more what i meant.

geek-merlin’s picture

Issue summary: View changes

Cleaned up and clarified.

geek-merlin’s picture

I 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.

dercheffe’s picture

In 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.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.