diff --git a/core/modules/field_layout/field_layout.install b/core/modules/field_layout/field_layout.install index 6b761bc..76d0ddf 100644 --- a/core/modules/field_layout/field_layout.install +++ b/core/modules/field_layout/field_layout.install @@ -30,3 +30,18 @@ function field_layout_install() { // Invalidate the render cache since all content will now have a layout. Cache::invalidateTags(['rendered']); } + +/** + * Implements hook_uninstall(). + */ +function field_layout_uninstall() { + // Remove field layout settings from all entity displays. + $config_factory = \Drupal::configFactory(); + $config_names = array_merge($config_factory->listAll('core.entity_view_display.'), $config_factory->listAll('core.entity_form_display.')); + foreach ($config_names as $name) { + $config_factory->getEditable($name)->clear('third_party_settings.field_layout')->save(TRUE); + } + + // Invalidate the render cache since all content will not have a layout. + Cache::invalidateTags(['rendered']); +} diff --git a/core/modules/field_layout/field_layout.module b/core/modules/field_layout/field_layout.module index 14cf931..7c0d864 100644 --- a/core/modules/field_layout/field_layout.module +++ b/core/modules/field_layout/field_layout.module @@ -108,21 +108,17 @@ function _field_layout_apply_layout(array &$build, EntityDisplayInterface $displ } // Add the regions to the $build in the correct order. - $regions = array_keys($layout_definition['regions']); - foreach ($regions as $region) { - $build[$region]['#theme_wrappers'][] = 'field_layout_region'; - $build[$region]['#region'] = $region; + foreach ($layout_definition['regions'] as $region => $region_info) { + $build['field_layout__' . $region]['#theme_wrappers'][] = 'field_layout_region'; + $build['field_layout__' . $region]['#region'] = $region; } - $field_layout = $display->getThirdPartySetting('field_layout', 'fields', []); - foreach ($display->getComponents() as $name => $component) { - if (isset($build[$name]) && isset($field_layout[$name]['region'])) { - $region = $field_layout[$name]['region']; - if ($region !== 'hidden') { - $build[$region][$name] = $build[$name]; - } - unset($build[$name]); + // Move the field from the top-level of $build into a region-specific section. + foreach ($display->getThirdPartySetting('field_layout', 'fields', []) as $name => $field) { + if (isset($build[$name]) && $field['region'] !== 'hidden') { + $build['field_layout__' . $field['region']][$name] = $build[$name]; } + unset($build[$name]); } } diff --git a/core/modules/field_layout/templates/field-layout-region.html.twig b/core/modules/field_layout/templates/field-layout-region.html.twig index 0c0b5d3..6969b5f 100644 --- a/core/modules/field_layout/templates/field-layout-region.html.twig +++ b/core/modules/field_layout/templates/field-layout-region.html.twig @@ -17,7 +17,7 @@ {% set classes = [ 'field-layout-region', -'field-layout-region-' ~ region|clean_class, +'field-layout-region--' ~ region|clean_class, ] %} {% if content %} diff --git a/core/modules/field_layout/tests/src/FunctionalJavascript/FieldLayoutTest.php b/core/modules/field_layout/tests/src/FunctionalJavascript/FieldLayoutTest.php index 705b769..09e8b3c 100644 --- a/core/modules/field_layout/tests/src/FunctionalJavascript/FieldLayoutTest.php +++ b/core/modules/field_layout/tests/src/FunctionalJavascript/FieldLayoutTest.php @@ -49,7 +49,7 @@ protected function setUp() { public function testEntityView() { // By default, the default layout is used. $this->drupalGet('node/1'); - $this->assertSession()->elementExists('css', '.field-layout-region-content .field--name-body'); + $this->assertSession()->elementExists('css', '.field-layout-region--content .field--name-body'); // The default layout is in use. $this->drupalGet('admin/structure/types/manage/article/display'); @@ -91,7 +91,12 @@ public function testEntityView() { // The new layout is used. $this->drupalGet('node/1'); - $this->assertSession()->elementExists('css', '.field-layout-region-left .field--name-body'); + $this->assertSession()->elementExists('css', '.field-layout-region--left .field--name-body'); + + // The layout is still in use without Field UI. + $this->container->get('module_installer')->uninstall(['field_ui']); + $this->drupalGet('node/1'); + $this->assertSession()->elementExists('css', '.field-layout-region--left .field--name-body'); } /**