Skip to content
This repository was archived by the owner on Jan 5, 2018. It is now read-only.

Commit 09e30a0

Browse files
committed
Move preparing the embed context to EntityHelperTrait::prepareEmbedContext.
1 parent 071f067 commit 09e30a0

File tree

2 files changed

+25
-30
lines changed

2 files changed

+25
-30
lines changed

src/EntityHelperTrait.php

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*

src/Form/EntityEmbedDialog.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,13 @@ public function buildForm(array $form, FormStateInterface $form_state, EditorInt
9090
$entity_element += $form_state->get('entity_element');
9191
$entity_element += array(
9292
'data-entity-type' => $embed_button->getTypeSetting('entity_type'),
93-
'data-entity-uuid' => '',
94-
'data-entity-id' => '',
95-
'data-entity-embed-display' => 'entity_reference:entity_reference_entity_view',
96-
'data-entity-embed-settings' => array(),
9793
'data-align' => '',
9894
);
99-
$form_state->set('entity_element', $entity_element);
10095
$form_state->set('entity', $this->loadEntity($entity_element['data-entity-type'], $entity_element['data-entity-uuid'] ?: $entity_element['data-entity-id']));
10196

97+
$this->prepareEmbedContext($entity_element, $form_state->get('entity'));
98+
$form_state->set('entity_element', $entity_element);
99+
102100
if (!$form_state->get('step')) {
103101
// If an entity has been selected, then always skip to the embed options.
104102
if ($form_state->get('entity')) {
@@ -250,12 +248,6 @@ public function buildEmbedStep(array $form, FormStateInterface $form_state) {
250248
$entity_element['data-entity-embed-display'] = key($display_plugin_options);
251249
}
252250

253-
// The default display plugin has been deprecated by the rendered entity
254-
// field formatter.
255-
if ($entity_element['data-entity-embed-display'] === 'default') {
256-
$entity_element['data-entity-embed-display'] = 'entity_reference:entity_reference_entity_view';
257-
}
258-
259251
$form['attributes']['data-entity-embed-display'] = array(
260252
'#type' => 'select',
261253
'#title' => $this->t('Display as'),

0 commit comments

Comments
 (0)