summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php12
-rw-r--r--core/modules/content_moderation/content_moderation.module16
-rw-r--r--core/modules/layout_builder/layout_builder.api.php32
-rw-r--r--core/modules/layout_builder/src/Form/OverridesEntityForm.php16
-rw-r--r--core/modules/layout_builder/tests/modules/layout_builder_test/layout_builder_test.module18
-rw-r--r--core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php3
6 files changed, 34 insertions, 63 deletions
diff --git a/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php b/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php
index 183e428..c282427 100644
--- a/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php
+++ b/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php
@@ -65,6 +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 $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.
@@ -72,7 +76,7 @@ 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) {
+ public static function collectRenderDisplay(FieldableEntityInterface $entity, $form_mode, $default_fallback = TRUE) {
$entity_type = $entity->getEntityTypeId();
$bundle = $entity->bundle();
@@ -82,7 +86,9 @@ class EntityFormDisplay extends EntityDisplayBase implements EntityFormDisplayIn
if ($form_mode != 'default') {
$candidate_ids[] = $entity_type . '.' . $bundle . '.' . $form_mode;
}
- $candidate_ids[] = $entity_type . '.' . $bundle . '.default';
+ if ($default_fallback) {
+ $candidate_ids[] = $entity_type . '.' . $bundle . '.default';
+ }
$results = \Drupal::entityQuery('entity_form_display')
->condition('id', $candidate_ids)
->condition('status', TRUE)
@@ -101,7 +107,7 @@ class EntityFormDisplay extends EntityDisplayBase implements EntityFormDisplayIn
$display = $storage->create([
'targetEntityType' => $entity_type,
'bundle' => $bundle,
- 'mode' => $form_mode,
+ 'mode' => $default_fallback ? $form_mode : static::CUSTOM_MODE,
'status' => TRUE,
]);
}
diff --git a/core/modules/content_moderation/content_moderation.module b/core/modules/content_moderation/content_moderation.module
index 8465753..18dae25 100644
--- a/core/modules/content_moderation/content_moderation.module
+++ b/core/modules/content_moderation/content_moderation.module
@@ -193,14 +193,16 @@ function content_moderation_entity_view(array &$build, EntityInterface $entity,
}
/**
- * Implements hook_layout_builder_overrides_entity_form_display_alter().
+ * Implements hook_entity_form_display_alter().
*/
-function content_moderation_layout_builder_overrides_entity_form_display_alter(EntityFormDisplayInterface $display) {
- $display->setComponent('moderation_state', [
- 'type' => 'moderation_state_default',
- 'weight' => -900,
- 'settings' => [],
- ]);
+function content_moderation_entity_form_display_alter(EntityFormDisplayInterface $form_display, array $context) {
+ if ($context['form_mode'] === 'layout_builder') {
+ $form_display->setComponent('moderation_state', [
+ 'type' => 'moderation_state_default',
+ 'weight' => -900,
+ 'settings' => [],
+ ]);
+ }
}
/**
diff --git a/core/modules/layout_builder/layout_builder.api.php b/core/modules/layout_builder/layout_builder.api.php
deleted file mode 100644
index 2e9d5f1..0000000
--- a/core/modules/layout_builder/layout_builder.api.php
+++ /dev/null
@@ -1,32 +0,0 @@
-<?php
-
-/**
- * @file
- * Hooks provided by the Layout Builder module.
- */
-
-/**
- * @addtogroup hooks
- * @{
- */
-
-/**
- * Allows customization of the Layout Builder UI for per-entity overrides.
- *
- * The Layout Builder widget will be added with a weight of -10 after this hook
- * is invoked.
- *
- * @see hook_entity_form_display_alter()
- * @see \Drupal\layout_builder\Form\OverridesEntityForm::init()
- */
-function hook_layout_builder_overrides_entity_form_display_alter(\Drupal\Core\Entity\Display\EntityFormDisplayInterface $display) {
- $display->setComponent('moderation_state', [
- 'type' => 'moderation_state_default',
- 'weight' => 2,
- 'settings' => [],
- ]);
-}
-
-/**
- * @} End of "addtogroup hooks".
- */
diff --git a/core/modules/layout_builder/src/Form/OverridesEntityForm.php b/core/modules/layout_builder/src/Form/OverridesEntityForm.php
index 6373e10..552fa59 100644
--- a/core/modules/layout_builder/src/Form/OverridesEntityForm.php
+++ b/core/modules/layout_builder/src/Form/OverridesEntityForm.php
@@ -76,24 +76,14 @@ class OverridesEntityForm extends ContentEntityForm {
protected function init(FormStateInterface $form_state) {
parent::init($form_state);
- // Create a transient display that is not persisted, but used only for
- // building the components required for the layout form.
- $display = EntityFormDisplay::create([
- 'targetEntityType' => $this->getEntity()->getEntityTypeId(),
- 'bundle' => $this->getEntity()->bundle(),
- ]);
-
- // Allow modules to choose if they are relevant to the layout form.
- $this->moduleHandler->alter('layout_builder_overrides_entity_form_display', $display);
-
- // Add the widget for Layout Builder after the alter.
- $display->setComponent(OverridesSectionStorage::FIELD_NAME, [
+ $form_display = EntityFormDisplay::collectRenderDisplay($this->entity, $this->getOperation(), FALSE);
+ $form_display->setComponent(OverridesSectionStorage::FIELD_NAME, [
'type' => 'layout_builder_widget',
'weight' => -10,
'settings' => [],
]);
- $this->setFormDisplay($display, $form_state);
+ $this->setFormDisplay($form_display, $form_state);
}
/**
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 9b26f57..bccf023 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,
+ ],
+ ]);
+ }
}
diff --git a/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php
index 7ce0e80..4c11a01 100644
--- a/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php
+++ b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php
@@ -85,6 +85,9 @@ class LayoutBuilderTest extends BrowserTestBase {
// Add a block with a custom label.
$this->drupalGet('node/1');
$page->clickLink('Layout');
+ // The layout form should not contain fields for the title of the node by
+ // default.
+ $assert_session->fieldNotExists('title[0][value]');
$page->clickLink('Add Block');
$page->clickLink('Powered by Drupal');
$page->fillField('settings[label]', 'This is an override');