diff --git a/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php b/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php index 0139bda8a7..c282427028 100644 --- a/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php +++ b/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php @@ -65,9 +65,10 @@ class EntityFormDisplay extends EntityDisplayBase implements EntityFormDisplayIn * The entity for which the form is being built. * @param string $form_mode * The form mode. - * @param bool $transient - * (optional) If the render display should be instantiated without - * attempting to load any display from configuration. Defaults to FALSE. + * @param bool $default_fallback + * (optional) Whether the default display should be used to initialize the + * form display in case the specified display does not exist. Defaults to + * TRUE. * * @return \Drupal\Core\Entity\Display\EntityFormDisplayInterface * The display object that should be used to build the entity form. @@ -75,30 +76,30 @@ class EntityFormDisplay extends EntityDisplayBase implements EntityFormDisplayIn * @see entity_get_form_display() * @see hook_entity_form_display_alter() */ - public static function collectRenderDisplay(FieldableEntityInterface $entity, $form_mode, $transient = FALSE) { + public static function collectRenderDisplay(FieldableEntityInterface $entity, $form_mode, $default_fallback = TRUE) { $entity_type = $entity->getEntityTypeId(); $bundle = $entity->bundle(); - $storage = \Drupal::entityManager()->getStorage('entity_form_display'); - if (!$transient) { - // Check the existence and status of: - // - the display for the form mode, - // - the 'default' display. - if ($form_mode != 'default') { - $candidate_ids[] = $entity_type . '.' . $bundle . '.' . $form_mode; - } + // Check the existence and status of: + // - the display for the form mode, + // - the 'default' display. + if ($form_mode != 'default') { + $candidate_ids[] = $entity_type . '.' . $bundle . '.' . $form_mode; + } + if ($default_fallback) { $candidate_ids[] = $entity_type . '.' . $bundle . '.default'; - $results = \Drupal::entityQuery('entity_form_display') - ->condition('id', $candidate_ids) - ->condition('status', TRUE) - ->execute(); - - // Load the first valid candidate display, if any. - foreach ($candidate_ids as $candidate_id) { - if (isset($results[$candidate_id])) { - $display = $storage->load($candidate_id); - break; - } + } + $results = \Drupal::entityQuery('entity_form_display') + ->condition('id', $candidate_ids) + ->condition('status', TRUE) + ->execute(); + + // Load the first valid candidate display, if any. + $storage = \Drupal::entityManager()->getStorage('entity_form_display'); + foreach ($candidate_ids as $candidate_id) { + if (isset($results[$candidate_id])) { + $display = $storage->load($candidate_id); + break; } } // Else create a fresh runtime object. @@ -106,9 +107,8 @@ public static function collectRenderDisplay(FieldableEntityInterface $entity, $f $display = $storage->create([ 'targetEntityType' => $entity_type, 'bundle' => $bundle, - 'mode' => $form_mode, + 'mode' => $default_fallback ? $form_mode : static::CUSTOM_MODE, 'status' => TRUE, - 'skipDisplayInitialization' => $transient, ]); } diff --git a/core/lib/Drupal/Core/Entity/EntityDisplayBase.php b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php index b97b30d990..e696a982fe 100644 --- a/core/lib/Drupal/Core/Entity/EntityDisplayBase.php +++ b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php @@ -56,13 +56,6 @@ */ protected $mode = self::CUSTOM_MODE; - /** - * Whether the display should be initialized or not. - * - * @var bool - */ - protected $skipDisplayInitialization = FALSE; - /** * Whether this display is enabled or not. If the entity (form) display * is disabled, we'll fall back to the 'default' display. @@ -160,7 +153,7 @@ public function __construct(array $values, $entity_type) { */ protected function init() { // Only populate defaults for "official" view modes and form modes. - if ($this->mode !== static::CUSTOM_MODE && !$this->skipDisplayInitialization) { + if ($this->mode !== static::CUSTOM_MODE) { $default_region = $this->getDefaultRegion(); // Fill in defaults for extra fields. $context = $this->displayContext == 'view' ? 'display' : $this->displayContext; diff --git a/core/modules/layout_builder/src/Form/OverridesEntityForm.php b/core/modules/layout_builder/src/Form/OverridesEntityForm.php index 4de7c4affd..552fa5910e 100644 --- a/core/modules/layout_builder/src/Form/OverridesEntityForm.php +++ b/core/modules/layout_builder/src/Form/OverridesEntityForm.php @@ -76,7 +76,7 @@ public function getBaseFormId() { protected function init(FormStateInterface $form_state) { parent::init($form_state); - $form_display = EntityFormDisplay::collectRenderDisplay($this->entity, $this->getOperation(), TRUE); + $form_display = EntityFormDisplay::collectRenderDisplay($this->entity, $this->getOperation(), FALSE); $form_display->setComponent(OverridesSectionStorage::FIELD_NAME, [ 'type' => 'layout_builder_widget', 'weight' => -10,