Skip to content

Commit 44ddeda

Browse files
committed
Issue #3023729 by tim.plunkett, bkosborne, xjm: LayoutBuilderController should iterate over components in a region using Element::children()
1 parent 6ee4f30 commit 44ddeda

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

modules/layout_builder/src/Controller/LayoutBuilderController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
77
use Drupal\Core\Messenger\MessengerInterface;
88
use Drupal\Core\Plugin\PluginFormInterface;
9+
use Drupal\Core\Render\Element;
910
use Drupal\Core\StringTranslation\StringTranslationTrait;
1011
use Drupal\Core\Url;
1112
use Drupal\layout_builder\Context\LayoutBuilderContextTrait;
@@ -209,7 +210,7 @@ protected function buildAdministrativeSection(SectionStorageInterface $section_s
209210

210211
foreach ($layout_definition->getRegions() as $region => $info) {
211212
if (!empty($build[$region])) {
212-
foreach ($build[$region] as $uuid => $block) {
213+
foreach (Element::children($build[$region]) as $uuid) {
213214
$build[$region][$uuid]['#attributes']['class'][] = 'draggable';
214215
$build[$region][$uuid]['#attributes']['data-layout-block-uuid'] = $uuid;
215216
$build[$region][$uuid]['#contextual_links'] = [
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Drupal\layout_builder_test\Plugin\Layout;
4+
5+
use Drupal\Core\Layout\LayoutDefault;
6+
7+
/**
8+
* @Layout(
9+
* id = "layout_builder_test_plugin",
10+
* label = @Translation("Layout Builder Test Plugin"),
11+
* regions = {
12+
* "main" = {
13+
* "label" = @Translation("Main Region")
14+
* }
15+
* },
16+
* )
17+
*/
18+
class LayoutBuilderTestPlugin extends LayoutDefault {
19+
20+
/**
21+
* {@inheritdoc}
22+
*/
23+
public function build(array $regions) {
24+
$build = parent::build($regions);
25+
$build['main']['#attributes']['class'][] = 'go-birds';
26+
return $build;
27+
}
28+
29+
}

modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,26 @@ public function testDeletedView() {
536536
$assert_session->pageTextNotContains('Test Block View');
537537
}
538538

539+
/**
540+
* Tests that sections can provide custom attributes.
541+
*/
542+
public function testCustomSectionAttributes() {
543+
$assert_session = $this->assertSession();
544+
$page = $this->getSession()->getPage();
545+
546+
$this->drupalLogin($this->drupalCreateUser([
547+
'configure any layout',
548+
'administer node display',
549+
]));
550+
551+
$this->drupalPostForm('admin/structure/types/manage/bundle_with_section_field/display/default', ['layout[enabled]' => TRUE], 'Save');
552+
$page->clickLink('Manage layout');
553+
$page->clickLink('Add Section');
554+
$page->clickLink('Layout Builder Test Plugin');
555+
// See \Drupal\layout_builder_test\Plugin\Layout\LayoutBuilderTestPlugin::build().
556+
$assert_session->elementExists('css', '.go-birds');
557+
}
558+
539559
/**
540560
* Tests the usage of placeholders for empty blocks.
541561
*

0 commit comments

Comments
 (0)