Skip to content
Snippets Groups Projects

Do not initialize components/customElementName for entities imported from config.

Merged Roderik Muit requested to merge issue/custom_elements-3443366:3443366-load-config into 3.x
1 unresolved thread
2 files
+ 35
28
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -69,31 +69,7 @@ class EntityCeDisplay extends EntityDisplayBase implements EntityCeDisplayInterf
* {@inheritdoc}
*/
public function postCreate(EntityStorageInterface $storage) {
if (!$this->targetEntityType) {
return;
}
// Enable components options as done in the regular entity_view_display.
$entity_view_display = \Drupal::service('entity_display.repository')
->getViewDisplay($this->targetEntityType, $this->bundle, $this->originalMode);
$field_definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions($this->targetEntityType, $this->bundle);
$custom_element = $this->ceGenerator->getViewModeDefaults($this->targetEntityType, $this->bundle, $this->originalMode);
$this->setCustomElementName($custom_element->getPrefixedTag());
// @todo Add support for statically set values.
// Enable every component with "auto" that is enabled in the display.
foreach ($entity_view_display->getComponents() as $name => $component) {
// Ignore extra-fields.
if (isset($field_definitions[$name])) {
$this->setComponent($name, [
'name' => $name,
'formatter' => 'auto',
'weight' => $component['weight'],
'region' => 'content',
'is_slot' => str_starts_with($field_definitions[$name]->getType(), 'text') ? 1 : 0,
]);
}
}
}
/**
@@ -196,8 +172,39 @@ class EntityCeDisplay extends EntityDisplayBase implements EntityCeDisplayInterf
* {@inheritdoc}
*/
protected function init() {
// Skip this.
// @todo Should this be used instead of ::postCreate()?
// Check if any components are present before doing other initialization.
$componentsPresent = !empty($this->content) || !empty($this->hidden);
parent::init();
if ($this->targetEntityType) {
if (!$this->getCustomElementName()) {
$custom_element = $this->ceGenerator->getViewModeDefaults($this->targetEntityType, $this->bundle, $this->originalMode);
$this->setCustomElementName($custom_element->getPrefixedTag());
}
if (!$componentsPresent) {
// Enable components options as done in the regular entity_view_display.
$entity_view_display = \Drupal::service('entity_display.repository')
->getViewDisplay($this->targetEntityType, $this->bundle, $this->originalMode);
$field_definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions($this->targetEntityType, $this->bundle);
// @todo Add support for statically set values.
// Enable every component with "auto" that is enabled in the display.
foreach ($entity_view_display->getComponents() as $name => $component) {
// Ignore extra-fields.
if (isset($field_definitions[$name])) {
$this->setComponent($name, [
'name' => $name,
'formatter' => 'auto',
'weight' => $component['weight'],
'region' => 'content',
'is_slot' => str_starts_with($field_definitions[$name]->getType(), 'text') ? 1 : 0,
]);
}
}
}
}
}
/**
Loading