@@ -162,25 +162,7 @@ protected function renderEntity(EntityInterface $entity, $view_mode, $langcode =
162162 * The HTML of the entity rendered with the display plugin.
163163 */
164164 protected function renderEntityEmbed (EntityInterface $ entity , array $ context = array ()) {
165- // Support the deprecated view-mode data attribute.
166- if (isset ($ context ['data-view-mode ' ]) && !isset ($ context ['data-entity-embed-display ' ]) && !isset ($ context ['data-entity-embed-settings ' ])) {
167- $ context ['data-entity-embed-display ' ] = 'entity_reference:entity_reference_entity_view ' ;
168- $ context ['data-entity-embed-settings ' ] = ['view_mode ' => &$ context ['data-view-mode ' ]];
169- }
170-
171- // Merge in default attributes.
172- $ context += array (
173- 'data-entity-id ' => $ entity ->id (),
174- 'data-entity-type ' => $ entity ->getEntityTypeId (),
175- 'data-entity-embed-display ' => 'entity_reference:entity_reference_entity_view ' ,
176- 'data-entity-embed-settings ' => array (),
177- );
178-
179- // The default display plugin has been deprecated by the rendered entity
180- // field formatter.
181- if ($ context ['data-entity-embed-display ' ] === 'default ' ) {
182- $ context ['data-entity-embed-display ' ] = 'entity_reference:entity_reference_entity_view ' ;
183- }
165+ $ this ->prepareEmbedContext ($ context , $ entity );
184166
185167 // Allow modules to alter the entity prior to embed rendering.
186168 $ this ->moduleHandler ()->alter (array ("{$ context ['data-entity-type ' ]}_embed_context " , 'entity_embed_context ' ), $ context , $ entity );
@@ -200,6 +182,27 @@ protected function renderEntityEmbed(EntityInterface $entity, array $context = a
200182 return $ entity_output ;
201183 }
202184
185+ protected function prepareEmbedContext (array &$ context , EntityInterface $ entity = null ) {
186+ // Merge in default attributes.
187+ $ context += array (
188+ 'data-entity-embed-display ' => EntityEmbedDisplayManagerInterface::DEFAULT_PLUGIN_ID ,
189+ 'data-entity-embed-settings ' => array (),
190+ 'data-entity-id ' => $ entity ? $ entity ->id () : '' ,
191+ 'data-entity-uuid ' => $ entity ? $ entity ->uuid () : '' ,
192+ 'data-entity-type ' => $ entity ? $ entity ->getEntityTypeId () : '' ,
193+ );
194+
195+ if ($ context ['data-entity-embed-display ' ] === 'default ' ) {
196+ // The default display plugin has been deprecated by the rendered entity
197+ // field formatter.
198+ $ context ['data-entity-embed-display ' ] = EntityEmbedDisplayManagerInterface::DEFAULT_PLUGIN_ID ;
199+ }
200+ elseif ($ context ['data-entity-embed-display ' ] === EntityEmbedDisplayManagerInterface::DEFAULT_PLUGIN_ID && isset ($ context ['data-view-mode ' ]) && empty ($ context ['data-entity-embed-settings ' ])) {
201+ // Support the deprecated view-mode data attribute.
202+ $ context ['data-entity-embed-settings ' ]['view_mode ' ] = &$ context ['data-view-mode ' ];
203+ }
204+ }
205+
203206 /**
204207 * Renders an entity using an EntityEmbedDisplay plugin.
205208 *
0 commit comments