diff --git a/core/modules/field_layout/tests/src/Functional/FieldLayoutTest.php b/core/modules/field_layout/tests/src/Functional/FieldLayoutTest.php index a12ae18ac059cfc3c81981127ab9c1286f55423b..058e6c361a43843a2889092328bfa64b46b13288 100644 --- a/core/modules/field_layout/tests/src/Functional/FieldLayoutTest.php +++ b/core/modules/field_layout/tests/src/Functional/FieldLayoutTest.php @@ -50,7 +50,7 @@ public function testNodeView() { // By default, the one-column layout is used. $this->drupalGet('node/1'); $this->assertSession()->elementExists('css', '.layout--onecol'); - $this->assertSession()->elementExists('css', '.layout-region--content .field--name-body'); + $this->assertSession()->elementExists('css', '.layout__region--content .field--name-body'); $this->drupalGet('admin/structure/types/manage/article/display'); $this->assertEquals(['Content', 'Disabled'], $this->getRegionTitles()); diff --git a/core/modules/field_layout/tests/src/FunctionalJavascript/FieldLayoutTest.php b/core/modules/field_layout/tests/src/FunctionalJavascript/FieldLayoutTest.php index a0fd13c0fa1126ccd9a7f9ca2370b1c60bb338d4..8ddbeafa0d744d05c53f08c08be972321a8a36d0 100644 --- a/core/modules/field_layout/tests/src/FunctionalJavascript/FieldLayoutTest.php +++ b/core/modules/field_layout/tests/src/FunctionalJavascript/FieldLayoutTest.php @@ -47,9 +47,9 @@ protected function setUp() { public function testEntityViewModes() { // By default, the field is not visible. $this->drupalGet('entity_test/1/test'); - $this->assertSession()->elementNotExists('css', '.layout-region--content .field--name-field-test-text'); + $this->assertSession()->elementNotExists('css', '.layout__region--content .field--name-field-test-text'); $this->drupalGet('entity_test/1'); - $this->assertSession()->elementNotExists('css', '.layout-region--content .field--name-field-test-text'); + $this->assertSession()->elementNotExists('css', '.layout__region--content .field--name-field-test-text'); // Change the layout for the "test" view mode. See // core.entity_view_mode.entity_test.test.yml. @@ -65,9 +65,9 @@ public function testEntityViewModes() { // Each view mode has a different layout. $this->drupalGet('entity_test/1/test'); - $this->assertSession()->elementExists('css', '.layout-region--content .field--name-field-test-text'); + $this->assertSession()->elementExists('css', '.layout__region--content .field--name-field-test-text'); $this->drupalGet('entity_test/1'); - $this->assertSession()->elementNotExists('css', '.layout-region--content .field--name-field-test-text'); + $this->assertSession()->elementNotExists('css', '.layout__region--content .field--name-field-test-text'); } /** @@ -90,46 +90,46 @@ public function testEntityForm() { // The field is moved to the default region for the new layout. $this->assertSession()->pageTextContains('Your settings have been saved.'); - $this->assertEquals(['Top', 'Left', 'Right', 'Bottom', 'Disabled'], $this->getRegionTitles()); + $this->assertEquals(['Top', 'First', 'Second', 'Bottom', 'Disabled'], $this->getRegionTitles()); $this->drupalGet('entity_test/manage/1/edit'); // No fields are visible, and the regions don't display when empty. - $this->assertFieldInRegion('field_test_text[0][value]', 'left'); - $this->assertSession()->elementExists('css', '.layout-region--left .field--name-field-test-text'); + $this->assertFieldInRegion('field_test_text[0][value]', 'first'); + $this->assertSession()->elementExists('css', '.layout__region--first .field--name-field-test-text'); // After a refresh the new regions are still there. $this->drupalGet('entity_test/structure/entity_test/form-display'); - $this->assertEquals(['Top', 'Left', 'Right', 'Bottom', 'Disabled'], $this->getRegionTitles()); + $this->assertEquals(['Top', 'First', 'Second', 'Bottom', 'Disabled'], $this->getRegionTitles()); - // Drag the field to the right region. + // Drag the field to the second region. $field_test_text_row = $this->getSession()->getPage()->find('css', '#field-test-text'); - $right_region_row = $this->getSession()->getPage()->find('css', '.region-right-message'); - $field_test_text_row->find('css', '.handle')->dragTo($right_region_row); + $second_region_row = $this->getSession()->getPage()->find('css', '.region-second-message'); + $field_test_text_row->find('css', '.handle')->dragTo($second_region_row); $this->assertSession()->assertWaitOnAjaxRequest(); $this->submitForm([], 'Save'); $this->assertSession()->pageTextContains('Your settings have been saved.'); // The new layout is used. $this->drupalGet('entity_test/manage/1/edit'); - $this->assertSession()->elementExists('css', '.layout-region--right .field--name-field-test-text'); - $this->assertFieldInRegion('field_test_text[0][value]', 'right'); + $this->assertSession()->elementExists('css', '.layout__region--second .field--name-field-test-text'); + $this->assertFieldInRegion('field_test_text[0][value]', 'second'); - // Move the field to the right region without tabledrag. + // Move the field to the second region without tabledrag. $this->drupalGet('entity_test/structure/entity_test/form-display'); $this->getSession()->getPage()->pressButton('Show row weights'); - $this->getSession()->getPage()->selectFieldOption('fields[field_test_text][region]', 'right'); + $this->getSession()->getPage()->selectFieldOption('fields[field_test_text][region]', 'second'); $this->assertSession()->assertWaitOnAjaxRequest(); $this->submitForm([], 'Save'); $this->assertSession()->pageTextContains('Your settings have been saved.'); // The updated region is used. $this->drupalGet('entity_test/manage/1/edit'); - $this->assertFieldInRegion('field_test_text[0][value]', 'right'); + $this->assertFieldInRegion('field_test_text[0][value]', 'second'); // The layout is still in use without Field UI. $this->container->get('module_installer')->uninstall(['field_ui']); $this->drupalGet('entity_test/manage/1/edit'); - $this->assertFieldInRegion('field_test_text[0][value]', 'right'); + $this->assertFieldInRegion('field_test_text[0][value]', 'second'); } /** @@ -147,23 +147,23 @@ public function testEntityView() { $this->submitForm([], 'Save'); $this->assertSession()->pageTextContains('Your settings have been saved.'); - $this->assertEquals(['Top', 'Left', 'Right', 'Bottom', 'Disabled'], $this->getRegionTitles()); + $this->assertEquals(['Top', 'First', 'Second', 'Bottom', 'Disabled'], $this->getRegionTitles()); $this->drupalGet('entity_test/1'); // No fields are visible, and the regions don't display when empty. $this->assertSession()->elementNotExists('css', '.layout--twocol'); - $this->assertSession()->elementNotExists('css', '.layout-region'); + $this->assertSession()->elementNotExists('css', '.layout__region'); $this->assertSession()->elementNotExists('css', '.field--name-field-test-text'); // After a refresh the new regions are still there. $this->drupalGet('entity_test/structure/entity_test/display'); - $this->assertEquals(['Top', 'Left', 'Right', 'Bottom', 'Disabled'], $this->getRegionTitles()); + $this->assertEquals(['Top', 'First', 'Second', 'Bottom', 'Disabled'], $this->getRegionTitles()); - // Drag the field to the left region. + // Drag the field to the first region. $this->assertTrue($this->assertSession()->optionExists('fields[field_test_text][region]', 'hidden')->isSelected()); $field_test_text_row = $this->getSession()->getPage()->find('css', '#field-test-text'); - $left_region_row = $this->getSession()->getPage()->find('css', '.region-left-message'); - $field_test_text_row->find('css', '.handle')->dragTo($left_region_row); + $first_region_row = $this->getSession()->getPage()->find('css', '.region-first-message'); + $field_test_text_row->find('css', '.handle')->dragTo($first_region_row); $this->assertSession()->assertWaitOnAjaxRequest(); $this->assertFalse($this->assertSession()->optionExists('fields[field_test_text][region]', 'hidden')->isSelected()); $this->submitForm([], 'Save'); @@ -172,25 +172,25 @@ public function testEntityView() { // The new layout is used. $this->drupalGet('entity_test/1'); $this->assertSession()->elementExists('css', '.layout--twocol'); - $this->assertSession()->elementExists('css', '.layout-region--left .field--name-field-test-text'); + $this->assertSession()->elementExists('css', '.layout__region--first .field--name-field-test-text'); - // Move the field to the right region without tabledrag. + // Move the field to the second region without tabledrag. $this->drupalGet('entity_test/structure/entity_test/display'); $this->getSession()->getPage()->pressButton('Show row weights'); - $this->getSession()->getPage()->selectFieldOption('fields[field_test_text][region]', 'right'); + $this->getSession()->getPage()->selectFieldOption('fields[field_test_text][region]', 'second'); $this->assertSession()->assertWaitOnAjaxRequest(); $this->submitForm([], 'Save'); $this->assertSession()->pageTextContains('Your settings have been saved.'); // The updated region is used. $this->drupalGet('entity_test/1'); - $this->assertSession()->elementExists('css', '.layout-region--right .field--name-field-test-text'); + $this->assertSession()->elementExists('css', '.layout__region--second .field--name-field-test-text'); // The layout is still in use without Field UI. $this->container->get('module_installer')->uninstall(['field_ui']); $this->drupalGet('entity_test/1'); $this->assertSession()->elementExists('css', '.layout--twocol'); - $this->assertSession()->elementExists('css', '.layout-region--right .field--name-field-test-text'); + $this->assertSession()->elementExists('css', '.layout__region--second .field--name-field-test-text'); } /** @@ -258,7 +258,7 @@ protected function getRegionTitles() { * The machine name of the region. */ protected function assertFieldInRegion($field_selector, $region_name) { - $region_element = $this->getSession()->getPage()->find('css', ".layout-region--$region_name"); + $region_element = $this->getSession()->getPage()->find('css', ".layout__region--$region_name"); $this->assertNotNull($region_element); $this->assertSession()->fieldExists($field_selector, $region_element); } diff --git a/core/modules/layout_discovery/layout_discovery.layouts.yml b/core/modules/layout_discovery/layout_discovery.layouts.yml index 98b1ed6126a43116a7c2d996c52de25793996a54..d1b0e5a3a832b703e96174bbbf6bc155db109317 100644 --- a/core/modules/layout_discovery/layout_discovery.layouts.yml +++ b/core/modules/layout_discovery/layout_discovery.layouts.yml @@ -15,14 +15,14 @@ layout_twocol: template: layout--twocol library: layout_discovery/twocol category: 'Columns: 2' - default_region: left + default_region: first regions: top: label: Top - left: - label: Left - right: - label: Right + first: + label: First + second: + label: Second bottom: label: Bottom @@ -36,16 +36,16 @@ layout_twocol_bricks: regions: top: label: Top - left_above: - label: 'Left above' - right_above: - label: 'Right above' + first_above: + label: 'First above' + second_above: + label: 'Second above' middle: label: Middle - left_below: - label: 'Left below' - right_below: - label: 'Right below' + first_below: + label: 'First below' + second_below: + label: 'Second below' bottom: label: Bottom @@ -55,16 +55,16 @@ layout_threecol_25_50_25: template: layout--threecol-25-50-25 library: layout_discovery/threecol_25_50_25 category: 'Columns: 3' - default_region: left + default_region: second regions: top: label: Top - left: - label: Left - middle: - label: Middle - right: - label: Right + first: + label: First + second: + label: Second + third: + label: Third bottom: label: Bottom @@ -74,15 +74,15 @@ layout_threecol_33_34_33: template: layout--threecol-33-34-33 library: layout_discovery/threecol_33_34_33 category: 'Columns: 3' - default_region: left + default_region: first regions: top: label: Top - left: - label: Left - middle: - label: Middle - right: - label: Right + first: + label: First + second: + label: Second + third: + label: Third bottom: label: Bottom diff --git a/core/modules/layout_discovery/layouts/onecol/layout--onecol.html.twig b/core/modules/layout_discovery/layouts/onecol/layout--onecol.html.twig index eb553cdf8a7c208c71a702efe1935aec1b51ecb4..64b9b4e5b9772b0a7f9cf00482eb05e675bee382 100644 --- a/core/modules/layout_discovery/layouts/onecol/layout--onecol.html.twig +++ b/core/modules/layout_discovery/layouts/onecol/layout--onecol.html.twig @@ -11,14 +11,15 @@ */ #} {% -set classes = [ -'layout--onecol', -] + set classes = [ + 'layout', + 'layout--onecol', + ] %} {% if content %} - -
- {{ content.content }} + +
+ {{ content.content }} +
- {% endif %} diff --git a/core/modules/layout_discovery/layouts/onecol/onecol.css b/core/modules/layout_discovery/layouts/onecol/onecol.css index 040b7f10c10aecf823a1b5e155232d60e0437ec3..e2283c5888777d1cf83450173b73ddc4c0d1f73a 100644 --- a/core/modules/layout_discovery/layouts/onecol/onecol.css +++ b/core/modules/layout_discovery/layouts/onecol/onecol.css @@ -1,3 +1,7 @@ -.layout--onecol .layout-region { +/* + * @file + * Provides the layout styles for layout_onecol. + */ +.layout--onecol .layout__region { width: 100%; } diff --git a/core/modules/layout_discovery/layouts/threecol_25_50_25/layout--threecol-25-50-25.html.twig b/core/modules/layout_discovery/layouts/threecol_25_50_25/layout--threecol-25-50-25.html.twig index 78db2b4b3237cc17c3ce63e2f997183abb52f7c7..85255252cef24a349a32ace87cedcf58af12bd2b 100644 --- a/core/modules/layout_discovery/layouts/threecol_25_50_25/layout--threecol-25-50-25.html.twig +++ b/core/modules/layout_discovery/layouts/threecol_25_50_25/layout--threecol-25-50-25.html.twig @@ -14,34 +14,41 @@ */ #} {% -set classes = [ -'layout--threecol', -] + set classes = [ + 'layout', + 'layout--threecol-25-50-25', + ] %} {% if content %} - - {% if content.top %} -
- {{ content.top }} -
- {% endif %} + + {% if content.top %} +
+ {{ content.top }} +
+ {% endif %} -
- {{ content.left }} -
+ {% if content.first %} +
+ {{ content.first }} +
+ {% endif %} -
- {{ content.middle }} -
+ {% if content.second %} +
+ {{ content.second }} +
+ {% endif %} -
- {{ content.right }} -
+ {% if content.third %} +
+ {{ content.third }} +
+ {% endif %} - {% if content.bottom %} -
- {{ content.bottom }} -
- {% endif %} - + {% if content.bottom %} +
+ {{ content.bottom }} +
+ {% endif %} + {% endif %} diff --git a/core/modules/layout_discovery/layouts/threecol_25_50_25/threecol_25_50_25.css b/core/modules/layout_discovery/layouts/threecol_25_50_25/threecol_25_50_25.css index 7472d55d66491ae02bbcd2eb41f612250f9dbd0f..1f41f460540bb4d15ebd48af527750f1c9f5fc3d 100644 --- a/core/modules/layout_discovery/layouts/threecol_25_50_25/threecol_25_50_25.css +++ b/core/modules/layout_discovery/layouts/threecol_25_50_25/threecol_25_50_25.css @@ -1,17 +1,26 @@ -.layout--threecol { +/* + * @file + * Provides the layout styles for layout_threecol_25_50_25. + * + * @todo Using display: flex requires https://www.drupal.org/node/2842298 to be + * in before this can be marked as stable. + */ +.layout--threecol-25-50-25 { display: flex; flex-wrap: wrap; - justify-content: space-between; } -.layout--threecol > .layout-region { - flex: 0 1 25%; -} - -.layout--threecol > .layout-region--fullwidth { +.layout--threecol-25-50-25 > .layout__region, +.layout--threecol-25-50-25 > .layout__region--second { flex: 0 1 100%; } -.layout--threecol > .layout-region--middle { - flex: 0 1 50%; +@media screen and (min-width: 40em) { + .layout--threecol-25-50-25 > .layout__region--first, + .layout--threecol-25-50-25 > .layout__region--third { + flex: 0 1 25%; + } + .layout--threecol-25-50-25 > .layout__region--second { + flex: 0 1 50%; + } } diff --git a/core/modules/layout_discovery/layouts/threecol_33_34_33/layout--threecol-33-34-33.html.twig b/core/modules/layout_discovery/layouts/threecol_33_34_33/layout--threecol-33-34-33.html.twig index 59461f42c2905ab27de330e545fcfacea686877c..5eabb040787079cdc1b165708edeced0e46d46a8 100644 --- a/core/modules/layout_discovery/layouts/threecol_33_34_33/layout--threecol-33-34-33.html.twig +++ b/core/modules/layout_discovery/layouts/threecol_33_34_33/layout--threecol-33-34-33.html.twig @@ -14,34 +14,41 @@ */ #} {% -set classes = [ -'layout--threecol-33', -] + set classes = [ + 'layout', + 'layout--threecol-33-34-33', + ] %} {% if content %} - - {% if content.top %} -
- {{ content.top }} -
- {% endif %} + + {% if content.top %} +
+ {{ content.top }} +
+ {% endif %} -
- {{ content.left }} -
+ {% if content.first %} +
+ {{ content.first }} +
+ {% endif %} -
- {{ content.middle }} -
+ {% if content.second %} +
+ {{ content.second }} +
+ {% endif %} -
- {{ content.right }} -
+ {% if content.third %} +
+ {{ content.third }} +
+ {% endif %} - {% if content.bottom %} -
- {{ content.bottom }} + {% if content.bottom %} +
+ {{ content.bottom }} +
+ {% endif %}
- {% endif %} - {% endif %} diff --git a/core/modules/layout_discovery/layouts/threecol_33_34_33/threecol_33_34_33.css b/core/modules/layout_discovery/layouts/threecol_33_34_33/threecol_33_34_33.css index 7091416fdfbb47b403c407c10e4480ede29d67a1..29a816fce5267e888431e42eb48113d6779daac3 100644 --- a/core/modules/layout_discovery/layouts/threecol_33_34_33/threecol_33_34_33.css +++ b/core/modules/layout_discovery/layouts/threecol_33_34_33/threecol_33_34_33.css @@ -1,13 +1,24 @@ -.layout--threecol-33 { +/* + * @file + * Provides the layout styles for layout_threecol_33_34_33. + * + * @todo Using display: flex requires https://www.drupal.org/node/2842298 to be + * in before this can be marked as stable. + */ + +.layout--threecol-33-34-33 { display: flex; flex-wrap: wrap; - justify-content: space-between; } -.layout--threecol-33 > .layout-region { - flex: 0 1 33%; +.layout--threecol-33-34-33 > .layout__region { + flex: 0 1 100%; } -.layout--threecol-33 > .layout-region--fullwidth { - flex: 0 1 100%; +@media screen and (min-width: 40em) { + .layout--threecol-33-34-33 > .layout__region--first, + .layout--threecol-33-34-33 > .layout__region--second, + .layout--threecol-33-34-33 > .layout__region--third { + flex: 0 1 33%; + } } diff --git a/core/modules/layout_discovery/layouts/twocol/layout--twocol.html.twig b/core/modules/layout_discovery/layouts/twocol/layout--twocol.html.twig index efebf0f95e3007c9ca73d09814778ab62166708c..b416cbd471ef2f8c238ddb38864bc05d0327c67a 100644 --- a/core/modules/layout_discovery/layouts/twocol/layout--twocol.html.twig +++ b/core/modules/layout_discovery/layouts/twocol/layout--twocol.html.twig @@ -11,26 +11,35 @@ */ #} {% -set classes = [ -'layout--twocol', -] + set classes = [ + 'layout', + 'layout--twocol', + ] %} {% if content %} -
- {{ content.top }} -
+ {% if content.top %} +
+ {{ content.top }} +
+ {% endif %} -
- {{ content.left }} -
+ {% if content.first %} +
+ {{ content.first }} +
+ {% endif %} -
- {{ content.right }} -
+ {% if content.second %} +
+ {{ content.second }} +
+ {% endif %} -
- {{ content.bottom }} -
+ {% if content.bottom %} +
+ {{ content.bottom }} +
+ {% endif %} {% endif %} diff --git a/core/modules/layout_discovery/layouts/twocol/twocol.css b/core/modules/layout_discovery/layouts/twocol/twocol.css index 41e8883ddf1e5399e2721a11a9be413098caf6a8..be9b59bb73a94528b58239843fb4531c86a67268 100644 --- a/core/modules/layout_discovery/layouts/twocol/twocol.css +++ b/core/modules/layout_discovery/layouts/twocol/twocol.css @@ -1,13 +1,23 @@ +/* + * @file + * Provides the layout styles for layout_twocol. + * + * @todo Using display: flex requires https://www.drupal.org/node/2842298 to be + * in before this can be marked as stable. + */ + .layout--twocol { display: flex; flex-wrap: wrap; - justify-content: space-between; } -.layout--twocol > .layout-region { - flex: 0 1 50%; +.layout--twocol > .layout__region { + flex: 0 1 100%; } -.layout--twocol > .layout-region--fullwidth { - flex: 0 1 100%; +@media screen and (min-width: 40em) { + .layout--twocol > .layout__region--first, + .layout--twocol > .layout__region--second { + flex: 0 1 50%; + } } diff --git a/core/modules/layout_discovery/layouts/twocol_bricks/layout--twocol-bricks.html.twig b/core/modules/layout_discovery/layouts/twocol_bricks/layout--twocol-bricks.html.twig index 9c6231b8b57f5ea706f81e628c5350b3e9c7fd55..10995771bfd91111ac0f14ec6d8ea02da8ec6012 100644 --- a/core/modules/layout_discovery/layouts/twocol_bricks/layout--twocol-bricks.html.twig +++ b/core/modules/layout_discovery/layouts/twocol_bricks/layout--twocol-bricks.html.twig @@ -14,38 +14,53 @@ */ #} {% -set classes = [ -'layout--twocol-bricks', -] + set classes = [ + 'layout', + 'layout--twocol-bricks', + ] %} {% if content %} - -
- {{ content.top }} -
+ + {% if content.top %} +
+ {{ content.top }} +
+ {% endif %} -
- {{ content.left_above }} -
+ {% if content.first_above %} +
+ {{ content.first_above }} +
+ {% endif %} -
- {{ content.right_above }} -
+ {% if content.second_above %} +
+ {{ content.second_above }} +
+ {% endif %} -
- {{ content.middle }} -
+ {% if content.middle %} +
+ {{ content.middle }} +
+ {% endif %} -
- {{ content.left_below }} -
+ {% if content.first_below %} +
+ {{ content.first_below }} +
+ {% endif %} -
- {{ content.right_below }} -
+ {% if content.second_below %} +
+ {{ content.second_below }} +
+ {% endif %} -
- {{ content.bottom }} + {% if content.bottom %} +
+ {{ content.bottom }} +
+ {% endif %}
- {% endif %} diff --git a/core/modules/layout_discovery/layouts/twocol_bricks/twocol_bricks.css b/core/modules/layout_discovery/layouts/twocol_bricks/twocol_bricks.css index aef887a4ac4bcae87021a8d0de6ecdeae15e7603..c8466aff7da4413b485a340f0226aa48c0aaea98 100644 --- a/core/modules/layout_discovery/layouts/twocol_bricks/twocol_bricks.css +++ b/core/modules/layout_discovery/layouts/twocol_bricks/twocol_bricks.css @@ -1,13 +1,25 @@ +/* + * @file + * Provides the layout styles for layout_twocol_bricks. + * + * @todo Using display: flex requires https://www.drupal.org/node/2842298 to be + * in before this can be marked as stable. + */ + .layout--twocol-bricks { display: flex; flex-wrap: wrap; - justify-content: space-between; } -.layout--twocol-bricks > .layout-region { - flex: 0 1 50%; +.layout--twocol-bricks > .layout__region { + flex: 0 1 100%; } -.layout--twocol-bricks > .layout-region--fullwidth { - flex: 0 1 100%; +@media screen and (min-width: 40em) { + .layout--twocol-bricks > .layout__region--first-above, + .layout--twocol-bricks > .layout__region--second-above, + .layout--twocol-bricks > .layout__region--first-below, + .layout--twocol-bricks > .layout__region--second-below { + flex: 0 1 50%; + } } diff --git a/core/modules/layout_discovery/templates/layout.html.twig b/core/modules/layout_discovery/templates/layout.html.twig index 88ea7457d4c59a8e144a7030677351f1666d2e30..6ba96d5ecda70492417d75afe05f64aee874db15 100644 --- a/core/modules/layout_discovery/templates/layout.html.twig +++ b/core/modules/layout_discovery/templates/layout.html.twig @@ -4,15 +4,20 @@ * Template for a generic layout. */ #} -{% set classes = [ - 'layout--' ~ layout.id|clean_class, -] %} +{% + set classes = [ + 'layout', + 'layout--' ~ layout.id|clean_class, + ] +%} {% if content %} - -{% for region in layout.getRegionNames %} -
- {{ content[region] }} + + {% for region in layout.getRegionNames %} + {% if content[region] %} +
+ {{ content[region] }} +
+ {% endif %} + {% endfor %}
-{% endfor %} - {% endif %} diff --git a/core/modules/layout_discovery/tests/src/Kernel/LayoutTest.php b/core/modules/layout_discovery/tests/src/Kernel/LayoutTest.php index 9d4c446d3ce0cddac8ac0b8121f115b88339dcb3..fa8fdd65637643950561c58e9f9bd01108eec6cd 100644 --- a/core/modules/layout_discovery/tests/src/Kernel/LayoutTest.php +++ b/core/modules/layout_discovery/tests/src/Kernel/LayoutTest.php @@ -38,12 +38,11 @@ protected function setUp() { * * @dataProvider renderLayoutData */ - public function testRenderLayout($layout_id, $config, $regions, $html) { + public function testRenderLayout($layout_id, $config, $regions, array $html) { $layout = $this->layoutPluginManager->createInstance($layout_id, $config); $built['layout'] = $layout->build($regions); - $built['layout']['#prefix'] = 'Test prefix'; - $built['layout']['#suffix'] = 'Test suffix'; - $html = 'Test prefix' . $html . "\n" . 'Test suffix'; + $built['layout']['#prefix'] = 'Test prefix' . "\n"; + $built['layout']['#suffix'] = 'Test suffix' . "\n"; // Assume each layout is contained by a form, in order to ensure the // building of the layout does not interfere with form processing. @@ -53,14 +52,40 @@ public function testRenderLayout($layout_id, $config, $regions, $html) { $form_builder->processForm('the_form_id', $built, $form_state); $this->render($built); - $this->assertRaw($html); - $this->assertRaw(''); + + // Add in the wrapping form elements and prefix/suffix. + array_unshift($html, 'Test prefix'); + array_unshift($html, '
'); + // Retrieve the build ID from the rendered HTML since the string is random. + $build_id_input = $this->cssSelect('input[name="form_build_id"]')[0]->asXML(); + $form_id_input = ''; + $html[] = 'Test suffix'; + $html[] = $build_id_input . $form_id_input . '
'; + + // Match the HTML to the full form element. + $this->assertSame(implode("\n", $html), $this->cssSelect('#the-form-id')[0]->asXML()); + } + + /** + * {@inheritdoc} + */ + protected function render(array &$elements) { + $content = parent::render($elements); + // Strip leading whitespace from every line. + $this->content = preg_replace('/^\s+/m', '', $content); + return $this->content; } /** * Data provider for testRenderLayout(). */ public function renderLayoutData() { + $html = []; + $html[] = '
'; + $html[] = '
'; + $html[] = 'This is the content'; + $html[] = '
'; + $html[] = '
'; $data['layout_onecol'] = [ 'layout_onecol', [], @@ -69,7 +94,18 @@ public function renderLayoutData() { '#markup' => 'This is the content', ], ], + $html, ]; + + $html = []; + $html[] = '
'; + $html[] = '
'; + $html[] = 'This string added by #process.'; + $html[] = '
'; + $html[] = '
'; + $html[] = 'This is the bottom'; + $html[] = '
'; + $html[] = '
'; $data['layout_test_1col_with_form'] = [ 'layout_test_1col', [], @@ -81,8 +117,18 @@ public function renderLayoutData() { '#markup' => 'This is the bottom', ], ], + $html, ]; + $html = []; + $html[] = '
'; + $html[] = '
'; + $html[] = 'This is the top'; + $html[] = '
'; + $html[] = '
'; + $html[] = 'This is the bottom'; + $html[] = '
'; + $html[] = '
'; $data['layout_test_1col'] = [ 'layout_test_1col', [], @@ -94,8 +140,18 @@ public function renderLayoutData() { '#markup' => 'This is the bottom', ], ], + $html, ]; + $html = []; + $html[] = '
'; + $html[] = '
'; + $html[] = 'This is the top'; + $html[] = '
'; + $html[] = '
'; + $html[] = 'This is the bottom'; + $html[] = '
'; + $html[] = '
'; $data['layout_test_1col_no_template'] = [ 'layout_test_1col_no_template', [], @@ -107,8 +163,18 @@ public function renderLayoutData() { '#markup' => 'This is the bottom', ], ], + $html, ]; + $html = []; + $html[] = '
'; + $html[] = '
'; + $html[] = 'This is the left'; + $html[] = '
'; + $html[] = '
'; + $html[] = 'This is the right'; + $html[] = '
'; + $html[] = '
'; $data['layout_test_2col'] = [ 'layout_test_2col', [], @@ -120,8 +186,19 @@ public function renderLayoutData() { '#markup' => 'This is the right', ], ], + $html, ]; + $html = []; + $html[] = '
'; + $html[] = '
'; + $html[] = 'Blah: '; + $html[] = 'Config value'; + $html[] = '
'; + $html[] = '
'; + $html[] = 'Main region'; + $html[] = '
'; + $html[] = '
'; $data['layout_test_plugin'] = [ 'layout_test_plugin', [ @@ -132,72 +209,9 @@ public function renderLayoutData() { '#markup' => 'Main region', ], ], + $html, ]; - $data['layout_onecol'][] = <<<'EOD' -
-
- This is the content -
-
-EOD; - - $data['layout_test_1col_with_form'][] = <<<'EOD' -
-
- This string added by #process. -
-
- This is the bottom -
-
-EOD; - - $data['layout_test_1col'][] = <<<'EOD' -
-
- This is the top -
-
- This is the bottom -
-
-EOD; - - $data['layout_test_1col_no_template'][] = <<<'EOD' -
-
- This is the top -
-
- This is the bottom -
-
-EOD; - - $data['layout_test_2col'][] = <<<'EOD' -
-
- This is the left -
-
- This is the right -
-
-EOD; - - $data['layout_test_plugin'][] = <<<'EOD' -
-
- Blah: - Config value -
-
- Main region -
-
-EOD; - return $data; }