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:
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.
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | 3026433-8.patch | 386 bytes | wim leers |
Comments
Comment #2
rjzaar commentedComment #3
rjzaar commentedIt 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....
Comment #4
wim leersComment #5
wim leersMarked #3033798: Editor preview does not use default theme templates as a duplicate of this.
Comment #6
wim leersNote: as #3033798 pointed out, #2678324: TypeError: Drupal.theme.bootstrapModal is not a function already fixed a similar problem for the rendering of the dialog itself.
Comment #7
wim leersAnd even though #2678324: TypeError: Drupal.theme.bootstrapModal is not a function fixed a related problem,
_theme: ajax_base_pageshould 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.previewroute. 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:
entity_embed's use of_theme: ajax_base_pageembed's use of_theme: ajax_base_pageand its incorrect theme selectionComment #8
wim leersComment #9
wim leersPer #7.2: #2844822-6: The preview in CKEditor does not use the same Twig template as the one on the front end (default theme).
Comment #10
wim leersGreen!
Comment #11
wim leers