diff --git a/core/config/schema/core.entity.schema.yml b/core/config/schema/core.entity.schema.yml index 8850d40ef7be..1ff2a19d7553 100644 --- a/core/config/schema/core.entity.schema.yml +++ b/core/config/schema/core.entity.schema.yml @@ -381,6 +381,12 @@ block.settings.field_block:*:*:*: formatter: type: field_formatter +block.settings.extra_field_block:*:*:*: + type: block_settings + mapping: + formatter: + type: field_formatter + # Schema for entity actions. action.configuration.entity:*:*: type: action_configuration_default diff --git a/core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php b/core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php index 8f3b02289998..c0288297f697 100644 --- a/core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php +++ b/core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php @@ -535,7 +535,7 @@ class LayoutBuilderEntityViewDisplay extends BaseEntityViewDisplay implements La foreach ($this->getSections() as $section) { foreach ($section->getComponents() as $component) { $plugin = $component->getPlugin(); - if ($plugin instanceof DerivativeInspectionInterface && $plugin->getBaseId() === 'field_block') { + if ($plugin instanceof DerivativeInspectionInterface && in_array($plugin->getBaseId(), ['field_block', 'extra_field_block'], TRUE)) { // FieldBlock derivative IDs are in the format // [entity_type]:[bundle]:[field]. list(, , $field_block_field_name) = explode(PluginBase::DERIVATIVE_SEPARATOR, $plugin->getDerivativeId()); diff --git a/core/modules/layout_builder/src/Plugin/Block/ExtraFieldBlock.php b/core/modules/layout_builder/src/Plugin/Block/ExtraFieldBlock.php index c42d628823ec..56875deb35f1 100644 --- a/core/modules/layout_builder/src/Plugin/Block/ExtraFieldBlock.php +++ b/core/modules/layout_builder/src/Plugin/Block/ExtraFieldBlock.php @@ -85,6 +85,10 @@ class ExtraFieldBlock extends BlockBase implements ContextAwarePluginInterface, public function defaultConfiguration() { return [ 'label_display' => FALSE, + 'formatter' => [ + 'settings' => [], + 'third_party_settings' => [], + ], ]; } 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 bccf0236bb3e..791034ddd6a8 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 @@ -47,6 +47,12 @@ function layout_builder_test_entity_extra_field_info() { 'description' => t('Extra description'), 'weight' => 0, ]; + $extra['node']['bundle_with_section_field']['display']['layout_builder_test_2'] = [ + 'label' => t('Extra Field 2'), + 'description' => t('Extra Field 2 description'), + 'weight' => 0, + 'visible' => FALSE, + ]; return $extra; } @@ -59,6 +65,11 @@ function layout_builder_test_node_view(array &$build, EntityInterface $entity, E '#markup' => 'Extra, Extra read all about it.', ]; } + if ($display->getComponent('layout_builder_test_2')) { + $build['layout_builder_test_2'] = [ + '#markup' => 'Extra Field 2 is hidden by default.', + ]; + } } /** diff --git a/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php index 36519a786323..3039e580776b 100644 --- a/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php +++ b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php @@ -904,6 +904,23 @@ class LayoutBuilderTest extends BrowserTestBase { $this->drupalGet('node'); $assert_session->linkExists('Read more'); + + // Consider an extra field hidden by default. Make sure it's not displayed. + $this->drupalGet('node/1'); + $assert_session->pageTextNotContains('Extra Field 2 is hidden by default.'); + + // View the layout and add the extra field that is not visible by default. + $this->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default/layout'); + $assert_session->pageTextNotContains('Extra Field 2'); + $page->clickLink('Add block'); + $page->clickLink('Extra Field 2'); + $page->pressButton('Add block'); + $assert_session->pageTextContains('Extra Field 2'); + $page->pressButton('Save layout'); + + // Confirm that the newly added extra field is visible. + $this->drupalGet('node/1'); + $assert_session->pageTextContains('Extra Field 2 is hidden by default.'); } /**