The editor (ckeditor) is correctly displaying the fields selected for a custom view mode but does not choose to use an available custom template for that view mode. Here are the steps to repeat the issue:
1) Install default D8
2) Create new view mode short.
3) Add short view mode to Article.
4) Manage display of short to only enable the body field as trimmed.
5) install entity_embed
6) Text Formats and Editors (Config) drag the Embed Node icon to the active toolbar for Full HTML and check 'Display embedded entities'.
7) Create 'Article 1' with a good amount of text in the body.
8) Create 'Article 2' with an embeded version of Article 1 as view mode short. This works.
9) install bootstrap theme
10) Add a custom template to bootstrap: node--article--short.html.twig
{%
set classes = [
node.bundle|clean_class,
node.isPromoted() ? 'is-promoted',
node.isSticky() ? 'is-sticky',
not node.isPublished() ? 'is-unpublished',
view_mode ? view_mode|clean_class,
'clearfix',
]
%}

This is short:

{{ content.body }}


11) Add a view which lists articles as ‘short’
12) For the view, when inspecting the html it correctly uses the custom template:

13) For Article 2 the rendered content is correct but when editing Article 2, ckeditor is not picking up the available template:

The editor should be displaying the embeded article using the custom template and it isn't.

CommentFileSizeAuthor
#8 3026433-8.patch386 byteswim leers

Comments

rjzaar created an issue. See original summary.

rjzaar’s picture

Issue summary: View changes
rjzaar’s picture

It appears that entity_embed is using the editor theme (the admin theme) as the context for displaying the entity within ckeditor rather than working out what theme would be used on the viewed node and using that theme. The current code respects the theme choice for the editor and thus can be the preferred functionality.
The first way is to try to manage the display of the view mode for the content type to create what was wanted by the custom template if possible.
The second way to provide the desired functionality (of this issue) is to sub-theme the editor theme and duplicate the templates for that theme. I have added templates to the editor theme and this works so I presume sub-theming would be a permanent solution.
A third way is to add functionality to entity_embed, eg a checkbox to the choose view mode dialog to permit a custom template that is used on the view of the node to be used in the ckeditor itself. In other words for this particular embeded entity, use the view theme (default site theme) and not the editor theme (admin theme).
Feel free to correct my understanding if I have made a mistake.

I have been able to get the second way working: https://github.com/rjzaar/opencourse/tree/8.6.x/docroot/themes/custom/oc....

wim leers’s picture

Title: Editor not displaying custom template for view mode » Text Editor using the admin theme instead of the default theme; hence custom template for view mode not used
Issue tags: -view mode, -custom template +DX (Developer Experience), +TX (Themer Experience)
wim leers’s picture

wim leers’s picture

wim leers’s picture

And even though #2678324: TypeError: Drupal.theme.bootstrapModal is not a function fixed a related problem, _theme: ajax_base_page should be removed as of #2745953: AjaxBasePageNegotiator should not require _theme: ajax_base_page to be specified, see the change record as to why: https://www.drupal.org/node/2752989. This was fixed in Drupal core 8.2.

However, all of that only applies to Entity Embed's dialog.

The bug reported here applies to the embed preview, which is generated by https://www.drupal.org/project/embed's embed.preview route. That too is using _theme: ajax_base_page, which was appropriate at the time but not anymore. We'll need to fix that in the Embed module. Which means this bug is one we need to fix in the Embed module too.

This led me to discover that in November 2018, I posted #2778355-10: TypeError: Drupal.theme.bootstrapModal is not a function, where I marked #2844822: The preview in CKEditor does not use the same Twig template as the one on the front end (default theme) as a duplicate of that. Even though I now realize that was wrong 😔 Turns out #2844822 actually was a predecessor of this issue's bug!

Is this confusing? Is this a mess? Yes and yes. I unfortunately didn't see the distinction between "Embed dialog using wrong theme" and "Embed preview using wrong theme" in #2778355-10: TypeError: Drupal.theme.bootstrapModal is not a function.

So, to clean this up, I'm:

  1. rescoping this issue to fix entity_embed's use of _theme: ajax_base_page
  2. rescoping #2844822: The preview in CKEditor does not use the same Twig template as the one on the front end (default theme) to fix embed's use of _theme: ajax_base_page and its incorrect theme selection
wim leers’s picture

Title: Text Editor using the admin theme instead of the default theme; hence custom template for view mode not used » entity_embed.dialog route should not use `_theme: ajax_base_page`
Component: CKEditor integration » User interface
Status: Active » Needs review
StatusFileSize
new386 bytes
wim leers’s picture

Title: entity_embed.dialog route should not use `_theme: ajax_base_page` » `entity_embed.dialog` route should not use `_theme: ajax_base_page`; no longer required as of Drupal 8.2
Category: Bug report » Task
Priority: Normal » Minor
Status: Needs review » Reviewed & tested by the community

Green!

wim leers’s picture

Component: User interface » Code
Status: Reviewed & tested by the community » Fixed

  • Wim Leers committed 92a6905 on 8.x-1.x
    Issue #3026433 by Wim Leers, rjzaar: `entity_embed.dialog` route should...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.