diff --git a/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php b/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php index 9d807dcbbc..0139bda8a7 100644 --- a/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php +++ b/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php @@ -106,8 +106,9 @@ public static function collectRenderDisplay(FieldableEntityInterface $entity, $f $display = $storage->create([ 'targetEntityType' => $entity_type, 'bundle' => $bundle, - 'mode' => $transient ? EntityDisplayBase::CUSTOM_MODE : $form_mode, + 'mode' => $form_mode, 'status' => TRUE, + 'skipDisplayInitialization' => $transient, ]); } diff --git a/core/lib/Drupal/Core/Entity/EntityDisplayBase.php b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php index e696a982fe..b97b30d990 100644 --- a/core/lib/Drupal/Core/Entity/EntityDisplayBase.php +++ b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php @@ -56,6 +56,13 @@ */ 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. @@ -153,7 +160,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) { + if ($this->mode !== static::CUSTOM_MODE && !$this->skipDisplayInitialization) { $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 a32502ad35..4de7c4affd 100644 --- a/core/modules/layout_builder/src/Form/OverridesEntityForm.php +++ b/core/modules/layout_builder/src/Form/OverridesEntityForm.php @@ -76,7 +76,6 @@ public function getBaseFormId() { protected function init(FormStateInterface $form_state) { parent::init($form_state); - $this->setOperation('layout_builder'); $form_display = EntityFormDisplay::collectRenderDisplay($this->entity, $this->getOperation(), TRUE); $form_display->setComponent(OverridesSectionStorage::FIELD_NAME, [ 'type' => 'layout_builder_widget', diff --git a/core/modules/layout_builder/tests/modules/layout_builder_test/layout_builder_test.module b/core/modules/layout_builder/tests/modules/layout_builder_test/layout_builder_test.module index 9b26f57d6a..bccf0236bb 100644 --- a/core/modules/layout_builder/tests/modules/layout_builder_test/layout_builder_test.module +++ b/core/modules/layout_builder/tests/modules/layout_builder_test/layout_builder_test.module @@ -83,13 +83,15 @@ function layout_builder_test_form_layout_builder_configure_block_alter(&$form, F } /** - * Implements hook_layout_builder_overrides_entity_form_display_alter(). + * Implements hook_entity_form_display_alter(). */ -function layout_builder_test_layout_builder_overrides_entity_form_display_alter(EntityFormDisplayInterface $display) { - $display->setComponent('status', [ - 'type' => 'boolean_checkbox', - 'settings' => [ - 'display_label' => TRUE, - ], - ]); +function layout_builder_entity_form_display_alter(EntityFormDisplayInterface $form_display, array $context) { + if ($context['form_mode'] === 'layout_builder') { + $form_display->setComponent('status', [ + 'type' => 'boolean_checkbox', + 'settings' => [ + 'display_label' => TRUE, + ], + ]); + } }